Skip to content

Commit a1f9026

Browse files
author
Yoshihiro Takahara
committed
test: Add test_validate_file_path for text editor
1 parent e1592fe commit a1f9026

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/test_text_editor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,16 @@ async def test_read_multiple_ranges_out_of_bounds_end(editor, test_file):
373373
assert second_range["end_line"] == 5
374374
assert second_range["total_lines"] == 5
375375
assert second_range["content_size"] == len(second_range["content"])
376+
377+
378+
@pytest.mark.asyncio
379+
async def test_validate_file_path(editor):
380+
"""Test file path validation."""
381+
# Valid path
382+
editor._validate_file_path("/path/to/file.txt")
383+
384+
# Test path traversal attempt
385+
with pytest.raises(ValueError, match="Path traversal not allowed"):
386+
editor._validate_file_path("../path/to/file.txt")
387+
with pytest.raises(ValueError, match="Path traversal not allowed"):
388+
editor._validate_file_path("folder/../file.txt")

0 commit comments

Comments
 (0)