diff --git a/JsonPreprocessor/CJsonPreprocessor.py b/JsonPreprocessor/CJsonPreprocessor.py index 4989acc..1cf0183 100644 --- a/JsonPreprocessor/CJsonPreprocessor.py +++ b/JsonPreprocessor/CJsonPreprocessor.py @@ -2148,6 +2148,23 @@ def __handleLastElement(sInput : str) -> str: self.__reset() raise Exception(f"{error} in line: '{line}'") line = line.rstrip() + # Check for Python inline code on left-hand side of colon (not allowed) + if '<<' in line and ':' in line: + # Check if any Python inline code pattern appears before any colon on the line + # This catches all forms: <<...>>, "<<...>>", ${<<...>>}, param[<<...>>], etc. + # Split by colon and check if left parts contain Python inline code + parts = line.split(':') + for i in range(len(parts) - 1): # All parts except the last could be key parts + left_part = parts[i] + if regex.search(r'<<.*?>>', left_part): + # Additional check: make sure this looks like a key part, not a value part + # Skip if this part seems to be continuing a previous value + stripped_left = left_part.strip() + # Simple heuristic: if it starts with a quote, comma, or common key patterns, it's likely a key + if (stripped_left.startswith(('"', "'", '${', ',')) or + regex.search(r'[{,]\s*[^,}]*$', stripped_left)): + self.__reset() + raise Exception("Python inline code on the left-hand side of the colon is generally not allowed.") # Checks the syntax of the Python inline code if '<<' in line or '>>' in line: patterns = [