From 6aa5302e36159685a704f01705ff9523caa50dda Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Thu, 12 Dec 2024 13:27:24 +0100 Subject: [PATCH] rewriter: extra check to see if produced names are valid (meaning: serializable/parseable) --- transformation/rewriter.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/transformation/rewriter.py b/transformation/rewriter.py index 33fa3c5..100073f 100644 --- a/transformation/rewriter.py +++ b/transformation/rewriter.py @@ -3,6 +3,7 @@ # - Change attribute values # - ? that's it? +import re from uuid import UUID from api.od import ODAPI, bind_api from services.bottom.V0 import Bottom @@ -13,6 +14,8 @@ from services.primitives.actioncode_type import ActionCode from services.primitives.integer_type import Integer from util.eval import exec_then_eval, simply_exec +identifier_regex_pattern = '[_A-Za-z][._A-Za-z0-9]*' +identifier_regex = re.compile(identifier_regex_pattern) class TryAgainNextRound(Exception): pass @@ -118,6 +121,8 @@ def rewrite(state, except: name_expr = f'"{rhs_name}"' # <- if the 'name' slot doesnt exist, use the pattern element name suggested_name = exec_then_eval(name_expr, _globals=eval_globals) + if not identifier_regex.match(suggested_name): + raise Exception(f"In the RHS pattern element '{rhs_name}', the following name-expression:\n {name_expr}\nproduced the name:\n '{suggested_name}'\nwhich contains illegal characters.\nNames should match the following regex: {identifier_regex_pattern}") rhs_type = rhs_odapi.get_type(rhs_obj) host_type = ramify.get_original_type(bottom, rhs_type) # for debugging: