Fix: Remove strip() from parameter value extraction to preserve indentation (#8739)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Xingyao Wang 2025-05-28 04:24:00 +08:00 committed by GitHub
parent 14498c5e25
commit 35f7efb9d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -582,7 +582,7 @@ def _extract_and_validate_params(
found_params = set()
for param_match in param_matches:
param_name = param_match.group(1)
param_value = param_match.group(2).strip()
param_value = param_match.group(2)
# Validate parameter is allowed
if allowed_params and param_name not in allowed_params:

View File

@ -652,6 +652,34 @@ NON_FNCALL_RESPONSE_MESSAGE = {
<parameter=command>view</parameter>
<parameter=path>/test/file.py</parameter>
<parameter=view_range>[1, 10]</parameter>
</function>""",
),
# Test case with indented code block to verify indentation is preserved
(
[
{
'index': 1,
'function': {
'arguments': '{"command": "str_replace", "path": "/test/file.py", "old_str": "def example():\\n pass", "new_str": "def example():\\n # This is indented\\n print(\\"hello\\")\\n return True"}',
'name': 'str_replace_editor',
},
'id': 'test_id',
'type': 'function',
}
],
"""<function=str_replace_editor>
<parameter=command>str_replace</parameter>
<parameter=path>/test/file.py</parameter>
<parameter=old_str>
def example():
pass
</parameter>
<parameter=new_str>
def example():
# This is indented
print("hello")
return True
</parameter>
</function>""",
),
],