fix: allow null device redirection in path scope

This commit is contained in:
陈家名 2026-06-12 14:02:47 +08:00
parent d229a9b022
commit b10d68d694
2 changed files with 11 additions and 0 deletions

View File

@ -59,6 +59,8 @@ class WorkspacePathScope:
def validate_path(self, candidate: str | Path, cwd: str | Path | None = None) -> PathScopeDecision:
raw = os.path.expandvars(os.path.expanduser(str(candidate)))
if raw == os.devnull:
return PathScopeDecision(True, 'null device is outside filesystem scope', str(candidate), raw)
if _is_windows_absolute(raw):
return self._validate_windows_path(raw)
base = Path(cwd).expanduser().resolve(strict=False) if cwd else self.roots[0]

View File

@ -94,6 +94,15 @@ class WorkspacePathScopeTests(unittest.TestCase):
self.assertFalse(decision.allowed)
self.assertIn(str(outside.resolve()), decision.resolved or '')
def test_null_device_redirection_is_allowed(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
workspace = Path(tmp) / 'workspace'
workspace.mkdir()
decision = WorkspacePathScope.from_root(workspace).validate_payload('echo ok >/dev/null')
self.assertTrue(decision.allowed, decision.reason)
def test_explicit_worktree_roots_are_allowed(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)