Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions JsonPreprocessor/CJsonPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ def __handleList(lInput : list, bNested : bool, parentParams : str = '') -> list
continue
keyPattern = regex.escape(k)
if regex.match(rf"^.+\['{keyPattern}'\]$", parentParams, regex.UNICODE):
parentParams = regex.sub(rf"\['{k}'\]", "", parentParams)
parentParams = regex.sub(rf"\['{keyPattern}'\]", "", parentParams)
elif not recursive:
parentParams = ''
__jsonUpdated(k, v, oJson, parentParams, keyNested, paramInValue, bDuplicatedHandle, recursive)
Expand Down Expand Up @@ -1465,7 +1465,7 @@ def __checkDotInParamName(self, oJson : dict):
if isinstance(v, dict):
self.__checkDotInParamName(v)

def __checkNestedParam(self, sInput : str, bKey=False, bCheckKeyName=False) -> bool:
def __checkNestedParam(self, sInput : str, bKey=False) -> bool:
"""
Checks nested parameter format.

Expand All @@ -1481,7 +1481,8 @@ def __checkNestedParam(self, sInput : str, bKey=False, bCheckKeyName=False) -> b
"""
pattern = rf"^\${{\s*[^{regex.escape(self.specialCharacters)}]+\s*}}(\[.*\])+$"
pattern1 = rf"\${{[^\${{]+}}(\[[^\[]+\])*[^\[]*\${{"
pattern2 = r"\[[a-zA-Z0-9\.\-\+\${}'\s]*:[a-zA-Z0-9\.\-\+\${}'\s]*\]" # Slicing pattern
pattern2 = r"\[[0-9\.\-\+'\s]*:[0-9\.\-\+'\s]*\]|\[[\s0-9\+\-]*\${.+[}\]][\s0-9\+\-]*:[\s0-9\+\-]*\${.+[}\]][\s0-9\+\-]*\]|" # Slicing pattern
pattern2 = pattern2 + r"\[[\s0-9\+\-]*\${.+[}\]][\s0-9\+\-]*:[0-9\.\-\+'\s]*\]|\[[0-9\.\-\+'\s]*:[\s0-9\+\-]*\${.+[}\]][\s0-9\+\-]*\]" # Slicing pattern
if CNameMangling.DYNAMICIMPORTED.value in sInput:
dynamicImported = regex.search(rf'^(.*){CNameMangling.DYNAMICIMPORTED.value}(.*)$', sInput)
sInput = dynamicImported[2]
Expand Down Expand Up @@ -2093,12 +2094,24 @@ def __handleLastElement(sInput : str) -> str:
sJsonDataUpdated = f"{sJsonDataUpdated}{line}\n"
sJsonDataUpdated = regex.sub(r'\[\s+\'', '[\'', sJsonDataUpdated)
sJsonDataUpdated = regex.sub(r'\'\s+\]', '\']', sJsonDataUpdated)
lKeyName = regex.findall(r'[,\s{]*("[^:,\n]*")\s*:\s*', sJsonDataUpdated)
lKeyName = regex.findall(r'[,\s{]*("[^"\n]*")\s*:\s*', sJsonDataUpdated)
tmpJsonDataUpdated = regex.sub(r":\s*\"[^\"]*\"", ": \"\"", sJsonDataUpdated)
tmpJsonDataUpdated = regex.sub(r"\[[^:]*:[^:]*\]", "[]", tmpJsonDataUpdated)
lKeyName = lKeyName + regex.findall(r'[,\s{]*(\${[^:,\n]+)\s*:\s*[^\]}]', tmpJsonDataUpdated)
for key in lKeyName:
if regex.match(r'^"\s+[^\s]+.+"$|^".+[^\s]+\s+"$', key):
newKey = '"' + key.strip('"').strip() + '"'
sJsonDataUpdated = sJsonDataUpdated.replace(key, newKey)
key = newKey
elif regex.match(r'^\s*\${.*$', key):
if key.count('${') != key.count('}'):
errorMsg = f"Invalid syntax: '{key.strip()}' - The curly brackets do not match."
self.__reset()
raise Exception(errorMsg)
elif key.count('[') != key.count(']'):
errorMsg = f"Invalid syntax: '{key.strip()}' - The square brackets do not match."
self.__reset()
raise Exception(errorMsg)
if r'\"' in key: # Ignore key name validation in case user converts a dictionary to string.
continue
keyDecode = bytes(key, 'utf-8').decode('utf-8')
Expand Down
Binary file modified JsonPreprocessor/JsonPreprocessor.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions JsonPreprocessor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
#
# Version and date of JsonPreprocessor
#
VERSION = "0.9.0"
VERSION_DATE = "14.3.2025"
VERSION = "0.9.1"
VERSION_DATE = "22.5.2025"

4 changes: 4 additions & 0 deletions packagedoc/additional_docs/History.tex
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@
- Improved and aligned error messages\newline
- Fixed bugs and updated the Selftest according to the changes}

\historyversiondate{0.9.1}{05/2025}
\historychange{- Enhanced cyclic import detection\newline
- Fixed bugs and updated error messages}

\end{packagehistory}