Skip to content

Comments

Fix emphasis delimiters inside link URLs#80

Closed
dereuromark wants to merge 1 commit intomasterfrom
fix/emphasis-delimiter-in-link-urls
Closed

Fix emphasis delimiters inside link URLs#80
dereuromark wants to merge 1 commit intomasterfrom
fix/emphasis-delimiter-in-link-urls

Conversation

@dereuromark
Copy link
Contributor

@dereuromark dereuromark commented Feb 8, 2026

Fixes #70
Upstream: jgm/djot#375

Problem

Emphasis delimiter scanning in parseDelimited() treats underscores/stars inside link URLs as emphasis closers:

_[link](http://example.com?foo_bar=1), more text_
→ <p><em>[link](http://example.com?foo</em>bar=1), more text_</p>

jgm confirmed this is a spec-level bug that should be fixed.

Fix

Added a findLinkEnd() helper (following the same pattern as existing findCodeSpanEnd() / findAutolinkEnd()) that parseDelimited() calls when it encounters [ or ![ during the forward scan. This skips over complete link constructs [text](url), [text][ref], and image variants, preventing delimiters inside URLs from interfering with emphasis matching.

Changed test expectations

Two official test expectations were updated to reflect the corrected behavior:

These will need to be synced once jgm updates the upstream spec tests.

Emphasis delimiter scanning in parseDelimited() now skips over link
underscores (or stars) inside link URLs from being treated as emphasis
closers.

Fixes #70
See also: jgm/djot#375
@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.77%. Comparing base (61ee4cd) to head (a068cd0).
⚠️ Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
src/Parser/InlineParser.php 97.14% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #80      +/-   ##
============================================
+ Coverage     93.42%   93.77%   +0.35%     
- Complexity     1956     2144     +188     
============================================
  Files            74       77       +3     
  Lines          5246     5719     +473     
============================================
+ Hits           4901     5363     +462     
- Misses          345      356      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dereuromark dereuromark added the bug Something isn't working label Feb 8, 2026
dereuromark added a commit that referenced this pull request Feb 9, 2026
Simpler alternative to PR #80 that only protects delimiters inside
link destinations `](...)`, without the full link lookahead.

Problem: Emphasis delimiters (`_`, `*`) inside link destinations were
matched as closers, breaking link formation:
  `_[link](http://example.com?foo_bar=1), more text_`
  → `<em>[link](http://example.com?foo</em>bar=1), more text_`

Fix: When scanning for emphasis closers in `parseDelimited()`, skip
over link destinations by detecting `](` and finding the matching `)`.
This prevents delimiters inside URLs from closing emphasis.

This is a targeted fix for the common real-world issue (URLs with
underscores in query parameters). It intentionally does NOT fix the
bracket-text case (`_[foo_](url)`) which remains emphasis - this
keeps the implementation simple per discussion in jgm/djot#375.

Refs: jgm/djot#375
@dereuromark
Copy link
Contributor Author

Closing in favor of #80 - keeping to the specs should be preferred.

@dereuromark dereuromark deleted the fix/emphasis-delimiter-in-link-urls branch February 17, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Djot-php parser doesn't recognise formatting if a link contains underscores

1 participant