Skip to content

fix: URL-decode link_path of markdown-style links#1

Open
sajalverma17 wants to merge 3 commits intothat0n3guy:mainfrom
sajalverma17:bugfix/url-decode-markdown-links-paths
Open

fix: URL-decode link_path of markdown-style links#1
sajalverma17 wants to merge 3 commits intothat0n3guy:mainfrom
sajalverma17:bugfix/url-decode-markdown-links-paths

Conversation

@sajalverma17
Copy link
Copy Markdown

Bug
get_backlinks_tool, get_outgoing_links_tool, and find_broken_links_tool are broken. There might be other tools depending on this part of links management that might also be broken.

Root cause
Markdown-style links have their link paths URL-encoded. For example, a Markdown-style link of Note With Spaces.md becomes [Note With Spaces](Note%20With%20Spaces.md) in the containing note.

links_management.py searches for markdown-style links using the MARKDOWN_LINK_PATTERN regex pattern. When it finds matches, it takes the link_path part of the link, and tries to equate it with the target note name provided in tool's query input. The link_path contains %20 and does not match with the note name provided in the input.

Fix
The fix uses unquote() to decode link paths, before matching them with provided target note name, returning correct backlinks and outgoing-links for notes with spaces in their names.
The fix is applied to extract_links_from_content() function, as well as get_backlinks tool.

Tests
The test suite looks like it is outdated. Nevertheless, I have added a unit test to test_link_management.py to verify the fix via extract_links_from_content() function.

Markdown-style links with spaces have their paths URL-encoded (e.g., Note With Spaces.md becomes [Note With Spaces](Note%20With%20Spaces.md)).
The fix uses unquote() to decode paths before matching them with provided target note name, returning correct backlinks and outgoing-links for notes
with spaces in their names.
@sajalverma17
Copy link
Copy Markdown
Author

Hello @that0n3guy

I wanted to follow up on this PR and confirm whether you agree with the bug diagnosis and proposed fix.

I believe this fix is minimal and addresses the root cause without introducing breaking changes. If you have any concerns about the approach or would like me to provide additional context (tests, documentation, etc.), I'm happy to make those changes.

Looking forward to your feedback.

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.

1 participant