From ed355b2b390d07c6b43437c6a9da6e05d5340e7d Mon Sep 17 00:00:00 2001 From: mas2hc Date: Wed, 2 Aug 2023 14:36:00 +0700 Subject: [PATCH 1/2] Add additional syntax precheck. --- JsonPreprocessor/CJsonPreprocessor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/JsonPreprocessor/CJsonPreprocessor.py b/JsonPreprocessor/CJsonPreprocessor.py index ca536060..fd7b1f7d 100644 --- a/JsonPreprocessor/CJsonPreprocessor.py +++ b/JsonPreprocessor/CJsonPreprocessor.py @@ -51,6 +51,7 @@ import sys import platform import copy +import shlex class CSyntaxType(): python = "python" @@ -707,6 +708,11 @@ def __handleListElements(sInput : str) -> str: for line in sJsonData.splitlines(): if line == '' or line.isspace(): continue + try: + listDummy = shlex.split(line) + except Exception as error: + raise Exception(f"\n[shlex exception]\n {str(error)} \nin line: '{line}'") + if re.search("\${.+}", line): items = re.split("\s*:\s*", line) newLine = "" From 83c1652bc10a1e8c0b4018ee9ddcb3d465cabe15 Mon Sep 17 00:00:00 2001 From: mas2hc Date: Wed, 2 Aug 2023 16:45:30 +0700 Subject: [PATCH 2/2] Update an exception message of syntax precheck method. --- JsonPreprocessor/CJsonPreprocessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JsonPreprocessor/CJsonPreprocessor.py b/JsonPreprocessor/CJsonPreprocessor.py index fd7b1f7d..82ac96ae 100644 --- a/JsonPreprocessor/CJsonPreprocessor.py +++ b/JsonPreprocessor/CJsonPreprocessor.py @@ -711,7 +711,7 @@ def __handleListElements(sInput : str) -> str: try: listDummy = shlex.split(line) except Exception as error: - raise Exception(f"\n[shlex exception]\n {str(error)} \nin line: '{line}'") + raise Exception(f"\n{str(error)} in line: '{line}'") if re.search("\${.+}", line): items = re.split("\s*:\s*", line)