Skip to content

fix: skip regex checks on autolink URLs - #152

Open
Kubudak90 wants to merge 1 commit into
ethereum:masterfrom
Kubudak90:fix/autolink-regex-clean
Open

fix: skip regex checks on autolink URLs#152
Kubudak90 wants to merge 1 commit into
ethereum:masterfrom
Kubudak90:fix/autolink-regex-clean

Conversation

@Kubudak90

Copy link
Copy Markdown

Fixes #91.

Autolinks like <https://example.com/eip7002> have their URL text incorrectly checked against regex patterns, causing false positives when URLs contain prohibited patterns (e.g. eip7002 matching the markdown-re-eip-dash regex).

Root Cause

The visitor pattern traverses all text nodes, including those inside autolinks. For autolinks, the URL itself becomes the text content and gets checked by enter_text, which shouldn't happen.

Solution

Use a stack-based approach to track link URLs:

  1. When entering a link, push its URL onto a stack
  2. When entering text, if text equals the top URL, it's an autolink — skip the pattern check
  3. When departing a link, pop the URL from the stack

This correctly handles:

  • Autolinks: <url> — URL text is not checked
  • Regular links: [text](url) — link text is still checked
  • Nested links: Stack handles nesting correctly

Testing

All existing tests pass, plus new tests verify:

  • Autolink URLs don't trigger false positives
  • Regular link text is still properly checked

Autolinks like <https://example.com/eip7002> have their URL text
incorrectly checked against regex patterns. This causes false positives
when URLs contain prohibited patterns.

The fix uses a stack-based approach:
- Push link URL onto stack when entering a link
- When entering text, if text equals the top URL, it's an autolink - skip it
- Pop URL from stack when departing the link

This correctly handles nested links and distinguishes between:
- Autolinks: <url> - URL text is not checked
- Regular links: [text](url) - link text is checked

Fixes ethereum#91
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