mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 20:34:45 +08:00
fix: issue 1138 windows encoding (#1139)
* fix(windows): use utf-8 for text file operations * fix(windows): normalize sandbox path masking * fix(windows): preserve utf-8 handling after backend split
This commit is contained in:
33
backend/tests/test_local_sandbox_encoding.py
Normal file
33
backend/tests/test_local_sandbox_encoding.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import builtins
|
||||
|
||||
import deerflow.sandbox.local.local_sandbox as local_sandbox
|
||||
from deerflow.sandbox.local.local_sandbox import LocalSandbox
|
||||
|
||||
|
||||
def _open(base, file, mode="r", *args, **kwargs):
|
||||
if "b" in mode:
|
||||
return base(file, mode, *args, **kwargs)
|
||||
return base(file, mode, *args, encoding=kwargs.pop("encoding", "gbk"), **kwargs)
|
||||
|
||||
|
||||
def test_read_file_uses_utf8_on_windows_locale(tmp_path, monkeypatch):
|
||||
path = tmp_path / "utf8.txt"
|
||||
text = "\u201cutf8\u201d"
|
||||
path.write_text(text, encoding="utf-8")
|
||||
base = builtins.open
|
||||
|
||||
monkeypatch.setattr(local_sandbox, "open", lambda file, mode="r", *args, **kwargs: _open(base, file, mode, *args, **kwargs), raising=False)
|
||||
|
||||
assert LocalSandbox("t").read_file(str(path)) == text
|
||||
|
||||
|
||||
def test_write_file_uses_utf8_on_windows_locale(tmp_path, monkeypatch):
|
||||
path = tmp_path / "utf8.txt"
|
||||
text = "emoji \U0001F600"
|
||||
base = builtins.open
|
||||
|
||||
monkeypatch.setattr(local_sandbox, "open", lambda file, mode="r", *args, **kwargs: _open(base, file, mode, *args, **kwargs), raising=False)
|
||||
|
||||
LocalSandbox("t").write_file(str(path), text)
|
||||
|
||||
assert path.read_text(encoding="utf-8") == text
|
||||
Reference in New Issue
Block a user