Skip to content

Commit 8435da7

Browse files
committed
Adds error message log for invalid format
1 parent f52d394 commit 8435da7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

JsonPreprocessor/CJsonPreprocessor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ def __loadNestedValue(initValue: str, sInputStr: str, bKey=False, key=''):
594594
elif re.match("^\s*" + pattern + "\s*$", sInputStr):
595595
sInputStr = re.sub("\$", "$$", sInputStr)
596596
else:
597+
self.__reset()
597598
while "str(" in initValue:
598599
initValue = re.sub("str\(([\${}0-9A-Za-z\.\-_\[\]]+)\)", "\\1", initValue, count=1)
599600
raise Exception(f"Invalid syntax! One or more than one opened or closed curly bracket is missing in expression '{initValue}'.\n \
@@ -669,6 +670,7 @@ def __loadNestedValue(initValue: str, sInputStr: str, bKey=False, key=''):
669670
k = re.sub("\$\$", "$", k)
670671
k = re.sub('^\s*\${\s*(.*?)\s*}', '\\1', keyAfterProcessed[0])
671672
elif k.count('{') != k.count('}'):
673+
self.__reset()
672674
raise Exception(f"Could not overwrite parameter {k} due to wrong format.\n \
673675
Please check key '{k}' in config file!!!")
674676

@@ -757,6 +759,8 @@ def __recursiveNestedHandling(sInputStr: str, lNestedParam: list) -> str:
757759
valueNumberPattern = "[0-9\.]+"
758760

759761
if "${" in sInputStr:
762+
if re.search("\[[0-9\s]*[A-Za-z_]+[0-9\s]*\]", sInputStr):
763+
raise Exception(f"Invalid syntax! A sub-element in {sInputStr.strip()} has to enclosed in quotes.")
760764
if re.match("^\s*" + nestedPattern + "\s*,*\]*}*\s*$", sInputStr.lower()):
761765
sInputStr = re.sub("(" + nestedPattern + ")", "\"\\1\"", sInputStr)
762766
nestedParam = re.sub("^\s*\"(.+)\"\s*.*$", "\\1", sInputStr)

0 commit comments

Comments
 (0)