Skip to content
Closed
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
17 changes: 17 additions & 0 deletions JsonPreprocessor/CJsonPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down