Fix issue with using an JSON object with single quote in a string when testing API tools.

Simply replacing the single quote with double quote will cause issue if some string in the JSON object contains single quotes.  This fixes the issue.
This commit is contained in:
Wei Mingzhi 2024-11-15 13:55:53 +08:00
parent 4322fdc910
commit 5c5483a7f0

View File

@ -263,12 +263,14 @@ class ApiTool(Tool):
elif property["type"] == "object" or property["type"] == "array": elif property["type"] == "object" or property["type"] == "array":
if isinstance(value, str): if isinstance(value, str):
try: try:
# an array str like '[1,2]' also can convert to list [1,2] through json.loads # an array str like '[1,2]' can also be converted to list [1,2] through json.loads
# json not support single quote, but we can support it # json does not support single quotes, but we can support it
value = value.replace("'", '"') return json.loads(value.replace("'", '"'))
return json.loads(value)
except ValueError: except ValueError:
return value try:
return json.loads(value)
except ValueError:
return value
elif isinstance(value, dict): elif isinstance(value, dict):
return value return value
else: else: