fix(files): treat BOM-only text as empty
This commit is contained in:
1 parent
e48f1ae65b
commit
a721806a50
2 files changed
+13
No files matched your search
@@ -375,6 +375,9 @@ class ReadFileTool(_FsTool):
|
|||||||
"Only supported text files and images can be read."
|
"Only supported text files and images can be read."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not text_content:
|
||||||
|
return f"(Empty file: {path})"
|
||||||
|
|
||||||
# Normalize CRLF -> LF before line-splitting. Primarily a Windows
|
# Normalize CRLF -> LF before line-splitting. Primarily a Windows
|
||||||
# concern (git checkouts with autocrlf, editors saving CRLF) but
|
# concern (git checkouts with autocrlf, editors saving CRLF) but
|
||||||
# applied on all platforms so downstream StrReplace/Grep behavior
|
# applied on all platforms so downstream StrReplace/Grep behavior
|
||||||
|
|||||||
@@ -138,6 +138,16 @@ class TestReadDedup:
|
|||||||
assert "2| Second line" in result
|
assert "2| Second line" in result
|
||||||
assert "\x00" not in result
|
assert "\x00" not in result
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("encoding", ["utf-8-sig", "utf-16", "utf-32"])
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_bom_only_unicode_text_is_empty_file(self, tool, tmp_path, encoding):
|
||||||
|
f = tmp_path / "empty.txt"
|
||||||
|
f.write_bytes("".encode(encoding))
|
||||||
|
|
||||||
|
result = await tool.execute(path=str(f))
|
||||||
|
|
||||||
|
assert result == f"(Empty file: {f})"
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Cross-session isolation (issue #3571)
|
# Cross-session isolation (issue #3571)
|
||||||
|
|||||||
Reference in new issue
Block a user