Repository navigation
Fix scan-root Markdown link resolution - #5674
sdivyanshu90 wants to merge 1 commit into
Conversation
Fixes Graphify-Labs#5672 Co-authored-by: OpenAI <[email protected]>
|
Thanks for the pull request, @sdivyanshu90. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
|
Thanks @sdivyanshu90! One small thing: our changelog and release notes are built from PR titles, so we use the conventional-commits format, for example: Prefixes we use: |
|
@safishamsi Could you please review this PR? |
There was a problem hiding this comment.
Graphify review 
1 bug · High impact
Markdown links beginning with / are resolved against the active scan root, with a containment check for paths handled this way.
Encoded leading slashes still resolve from the filesystem root ·
markdown.py:368
What this review covered
- We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
- A changed file's diff was too long to show in full, so the review may not have seen every changed line in it; the in-depth pass still reviewed every changed file.
- 3 of 3 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 4174 functions depend on this change
- 666 of 666 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed cfc1485
| return None | ||
| link_root = None | ||
| if not wikilink: | ||
| # Decoding can reveal a scheme or a protocol-relative prefix | ||
| # (%2F%2Fhost), so the external-link guard runs again. | ||
| if target.startswith("/") and (scan_root := _active_scan_root()) is not None: |
There was a problem hiding this comment.
Encoded leading slashes still resolve from the filesystem root
A Markdown link whose leading slash is percent-encoded can point outside the scan root instead of resolving from the project root.
Handle decoded leading slashes like literal leading slashes in _resolve_markdown_link.
Evidence · checked against the code
Expected: The decoded target resolves beneath the scan root, like a literal leading-slash link.
Actually: The decoded target is an absolute path and is returned without being anchored to the scan root.
- Independent source review: The literal
/docs/guide.mdpath is handled by the new scan-root branch, which switches the source directory to the scan root and strips the leading slash. That guard does not apply to%2Fdocs/guide.md. The inspected tests cover percent-decoded external prefixes and ordinary percent-decoded filenames, but do not exercise an encoded leading slash with an active scan root.
Prompt to fix with AI
In graphify/extractors/markdown.py, _resolve_markdown_link (lines 365-368):
Problem: Encoded leading slashes still resolve from the filesystem root
Expected: The decoded target resolves beneath the scan root, like a literal leading-slash link.
Actually: The decoded target is an absolute path and is returned without being anchored to the scan root.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
Fixes #5672
Summary
Validation
referencesedges. Both scan-root edges are missing on upstream and present with this change.python -m pytest -q tests/test_markdown*.py→ 75 passed.ruff check .→ passed.python -m pyright --outputjson→ same diagnostics as clean upstream (1,258 errors and 241 warnings in this environment).python -m graphify update .→ completed.python -m pytest tests -q→ 12,592 passed, 147 skipped, 2 xfailed, and 17 failures. The same 17 tests fail on clean upstream in this environment.