Skip to content

Fix percent sign in quoted attribute values being treated as comment#109

Merged
dereuromark merged 2 commits intomasterfrom
fix/percent-in-quoted-values
Mar 23, 2026
Merged

Fix percent sign in quoted attribute values being treated as comment#109
dereuromark merged 2 commits intomasterfrom
fix/percent-in-quoted-values

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Summary

  • Fixes bug where % inside quoted attribute values (e.g., title="100% done") was incorrectly treated as a comment marker
  • The previous regex-based removeComments() stripped all content between % markers without considering quotes
  • Rewrites removeComments() to be quote-aware by scanning character-by-character
  • Quoted strings are now copied verbatim, preserving literal % characters inside them

Before:

Input:  [text]{title="100% done"}
Output: <p><span>text</span></p>  ← title attribute was stripped

After:

Input:  [text]{title="100% done"}
Output: <p><span title="100% done">text</span></p>  ✓

Verified against reference JS implementation (@djot/djot).

Changes

  • src/Parser/Utility/AttributeParser.php: Rewrite removeComments() to be quote-aware
  • tests/TestCase/Parser/AttributeParserTest.php: Add 7 tests for percent signs in quoted values

The removeComments() method was using a simple regex that stripped all
content between % markers, including those inside quoted attribute
values like title="100% done".

This rewrites removeComments() to be quote-aware by scanning character
by character and copying quoted strings verbatim. Percent signs inside
quotes are now preserved as literal characters.

Adds 7 tests for percent signs in quoted values.
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.61%. Comparing base (274c09f) to head (27fe8aa).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #109      +/-   ##
============================================
+ Coverage     93.57%   93.61%   +0.03%     
- Complexity     2316     2328      +12     
============================================
  Files            79       79              
  Lines          6134     6168      +34     
============================================
+ Hits           5740     5774      +34     
  Misses          394      394              

☔ 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 merged commit e35734f into master Mar 23, 2026
6 checks passed
@dereuromark dereuromark deleted the fix/percent-in-quoted-values branch March 23, 2026 06:14
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