changes
This commit is contained in:
@@ -321,17 +321,34 @@ def resolve_value(expr, context):
|
||||
# =============================================
|
||||
# $append(list, element)
|
||||
if re.match(r'^\$append\(', expr, re.IGNORECASE):
|
||||
match = re.match(r'^\$append\((.*)\)$', expr, re.IGNORECASE)
|
||||
match = re.match(r"^\$append\(([^,]+),\s*(.+)\)$", expr, re.DOTALL)
|
||||
if match:
|
||||
args = split_args(match.group(1))
|
||||
if len(args) == 2:
|
||||
target_list = resolve_value(args[0], context)
|
||||
element = resolve_value(args[1], context)
|
||||
if not isinstance(target_list, list):
|
||||
target_list = []
|
||||
result = list(target_list)
|
||||
result.append(element)
|
||||
return result
|
||||
list_expr = match.group(1).strip()
|
||||
element_expr = match.group(2).strip()
|
||||
|
||||
# 1. Resolve the list
|
||||
target_list = resolve_value(list_expr, context)
|
||||
if target_list is None:
|
||||
target_list = []
|
||||
|
||||
# Ensure it's a copy so we don't modify the original context variable directly
|
||||
target_list = list(target_list)
|
||||
|
||||
# 2. Resolve the element
|
||||
resolved_element = resolve_value(element_expr, context)
|
||||
|
||||
if isinstance(resolved_element, str):
|
||||
try:
|
||||
import json
|
||||
element_to_append = json.loads(resolved_element)
|
||||
except json.JSONDecodeError:
|
||||
element_to_append = resolved_element
|
||||
else:
|
||||
element_to_append = resolved_element
|
||||
|
||||
target_list.append(element_to_append)
|
||||
return target_list
|
||||
|
||||
|
||||
# $first(list), $last(list)
|
||||
if re.match(r'^\$(first|last)\(', expr, re.IGNORECASE):
|
||||
|
||||
Reference in New Issue
Block a user