mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #846 from ynput/bugfix/fix_anatomy_format
Validate opening and closing brackets on Anatomy keys.
This commit is contained in:
commit
874a0f1c4e
1 changed files with 34 additions and 0 deletions
|
|
@ -460,6 +460,34 @@ class FormattingPart:
|
|||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def validate_key_is_matched(key):
|
||||
"""Validate that opening has closing at correct place.
|
||||
Future-proof, only square brackets are currently used in keys.
|
||||
|
||||
Example:
|
||||
>>> is_matched("[]()()(((([])))")
|
||||
False
|
||||
>>> is_matched("[](){{{[]}}}")
|
||||
True
|
||||
|
||||
Returns:
|
||||
bool: Openings and closing are valid.
|
||||
|
||||
"""
|
||||
mapping = dict(zip("({[", ")}]"))
|
||||
opening = set(mapping.keys())
|
||||
closing = set(mapping.values())
|
||||
queue = []
|
||||
|
||||
for letter in key:
|
||||
if letter in opening:
|
||||
queue.append(mapping[letter])
|
||||
elif letter in closing:
|
||||
if not queue or letter != queue.pop():
|
||||
return False
|
||||
return not queue
|
||||
|
||||
def format(self, data, result):
|
||||
"""Format the formattings string.
|
||||
|
||||
|
|
@ -472,6 +500,12 @@ class FormattingPart:
|
|||
result.add_output(result.realy_used_values[key])
|
||||
return result
|
||||
|
||||
# ensure key is properly formed [({})] properly closed.
|
||||
if not self.validate_key_is_matched(key):
|
||||
result.add_missing_key(key)
|
||||
result.add_output(self.template)
|
||||
return result
|
||||
|
||||
# check if key expects subdictionary keys (e.g. project[name])
|
||||
existence_check = key
|
||||
key_padding = list(KEY_PADDING_PATTERN.findall(existence_check))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue