Merge b1a5062eb6
into a30945312a
This commit is contained in:
commit
8d2aa05e42
@ -168,6 +168,20 @@ class VariablePool(BaseModel):
|
|||||||
segments.append(variable_factory.build_segment(part))
|
segments.append(variable_factory.build_segment(part))
|
||||||
return SegmentGroup(value=segments)
|
return SegmentGroup(value=segments)
|
||||||
|
|
||||||
|
def convert_template_escape(self, template: str, /):
|
||||||
|
parts = VARIABLE_PATTERN.split(template)
|
||||||
|
segments = []
|
||||||
|
for part in filter(lambda x: x, parts):
|
||||||
|
if "." in part and (variable := self.get(part.split("."))):
|
||||||
|
if isinstance(variable.value, str):
|
||||||
|
escape_string = variable.value.replace('"', '\\"').replace('\n', '\\n')
|
||||||
|
segments.append(variable_factory.build_segment(escape_string))
|
||||||
|
else:
|
||||||
|
segments.append(variable)
|
||||||
|
else:
|
||||||
|
segments.append(variable_factory.build_segment(part))
|
||||||
|
return SegmentGroup(value=segments)
|
||||||
|
|
||||||
def get_file(self, selector: Sequence[str], /) -> FileSegment | None:
|
def get_file(self, selector: Sequence[str], /) -> FileSegment | None:
|
||||||
segment = self.get(selector)
|
segment = self.get(selector)
|
||||||
if isinstance(segment, FileSegment):
|
if isinstance(segment, FileSegment):
|
||||||
|
@ -173,7 +173,7 @@ class Executor:
|
|||||||
case "json":
|
case "json":
|
||||||
if len(data) != 1:
|
if len(data) != 1:
|
||||||
raise RequestBodyError("json body type should have exactly one item")
|
raise RequestBodyError("json body type should have exactly one item")
|
||||||
json_string = self.variable_pool.convert_template(data[0].value).text
|
json_string = self.variable_pool.convert_template_escape(data[0].value).text
|
||||||
try:
|
try:
|
||||||
json_object = json.loads(json_string, strict=False)
|
json_object = json.loads(json_string, strict=False)
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user