Skip to content

fix(viewer): percent-decode link targets in _extract_links - #203

Open
oierreaemme wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
oierreaemme:fix/viewer-percent-decode-links
Open

fix(viewer): percent-decode link targets in _extract_links#203
oierreaemme wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
oierreaemme:fix/viewer-percent-decode-links

Conversation

@oierreaemme

Copy link
Copy Markdown

Fixes #200

Problem

Per SPEC §5, links to file names containing spaces are percent-encoded (e.g. [report](weekly%20report.md)). _extract_links in okf/src/reference_agent/viewer/generator.py resolves the raw regex capture without decoding it, so the emitted edge id is notes/weekly%20report while the concept node id derived from the on-disk path is notes/weekly report. The edge never matches a node and is dropped: a bundle whose file names contain spaces renders with zero edges even though every link is spec-conformant.

Fix

Decode the captured target with urllib.parse.unquote before resolving it. Decoding happens before the scheme/absolute-path guards, so percent-encoded forms of external (https%3A%2F%2F…) or absolute (%2F…) targets are still skipped. Targets containing a literal % not followed by two hex digits are left untouched by unquote.

Scope

Deliberately minimal:

Testing

okf/tests/test_viewer.py: 7 passed (6 existing + new regression test test_percent_encoded_links_become_edges, which fails without the fix).

Per SPEC section 5, links to file names containing spaces are
percent-encoded (e.g. `[report](weekly%20report.md)`). _extract_links
resolved the raw target without decoding, producing edge ids like
`notes/weekly%20report` that never match the concept ids derived from
on-disk paths (`notes/weekly report`), so every such edge was dropped:
bundles whose file names contain spaces render with zero edges.

Decode the captured target with urllib.parse.unquote before resolving.
Decoding happens before the scheme/absolute-path checks so encoded
forms of external or absolute targets are still skipped.

Scoped fix: absolute bundle-relative links remain unsupported here
(tracked separately in GoogleCloudPlatform#48). Adds a regression test.

Fixes GoogleCloudPlatform#200
@google-cla

google-cla Bot commented Jul 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@oierreaemme

Copy link
Copy Markdown
Author

@googlebot I signed it!

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.

visualize: percent-encoded link targets are never decoded — bundles with spaces in filenames render with 0 edges

1 participant