Skip to content

chore(compile): tighten link_resolver._resolve_path input guards#991

Open
mvanhorn wants to merge 1 commit intomicrosoft:mainfrom
mvanhorn:fix/841-link-resolver-input-guards
Open

chore(compile): tighten link_resolver._resolve_path input guards#991
mvanhorn wants to merge 1 commit intomicrosoft:mainfrom
mvanhorn:fix/841-link-resolver-input-guards

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Closes #841.

Summary

Adds an early-return guard for empty / whitespace-only input in `_resolve_path` (Minor 1 + Minor 2 from the issue). Previously `_resolve_path("")` and `_resolve_path(" ")` returned the base directory via `Path(base_dir) / ""`, which is semantically wrong even though the existing `.exists()` checks in the call sites masked the bug.

```python
if not path or not path.strip():
return None
```

Tests (Minor 3)

Adds `TestResolvePathInputGuards` to `tests/unit/compilation/test_link_resolver.py` covering each case the issue called out:

  • empty string -> `None` (new guard)
  • whitespace-only (spaces, tab, newline) -> `None` (new guard)
  • embedded NUL byte -> must not crash; the containment check is the caller's job, so the test only locks in "no exception"
  • POSIX backslash traversal (`foo\\..\\..\\etc\\passwd`) -> stays a literal segment under `base_dir`
  • `file://` URI on POSIX -> treated relative, joined under `base_dir`
  • non-existent relative target -> resolves normally (happy path)

Verification

`pytest tests/unit/compilation/test_link_resolver.py` -> 23 / 23 pass (17 existing + 6 new).

Adds an early-return guard for empty / whitespace-only input. Previously
`_resolve_path("")` and `_resolve_path("   ")` returned the base directory
via `Path(base_dir) / ""`, which is semantically wrong (an empty link
should resolve to nothing) even though existing callers' `.exists()` check
masked the bug.

Adds a TestResolvePathInputGuards class that locks in the behaviour for:

- empty string
- whitespace-only (spaces, tab, newline)
- embedded NUL byte (must not crash; containment is the caller's job)
- POSIX backslash traversal (literal segment, stays under base_dir)
- file:// URI on POSIX (treated relative, joined under base_dir)
- non-existent relative target (happy path)

Closes microsoft#841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(compile): tighten link_resolver._resolve_path input guards

1 participant