Skip to content

Split class attributes on any whitespace in hasClass(), removeClass() and .class selectors - #164

Open
samipuro wants to merge 1 commit into
GravityPDF:mainfrom
samipuro:fix/class-attribute-whitespace
Open

samipuro wants to merge 1 commit into
GravityPDF:mainfrom
samipuro:fix/class-attribute-whitespace

Conversation

@samipuro

@samipuro samipuro commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Pull Request type

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

hasClass(), removeClass() and a class selector with no element name (find('.one'), html5qp($html, '.one')) split the class attribute on spaces only. The HTML parsers keep tabs and newlines in attribute values, so a class separated from the others by one of those is not found:

$html = "<html><body><p class=\"one\n  two\">a</p></body></html>";
html5qp($html)->find('.one')->count();                  // 0, while find('p.one') finds 1
html5qp($html, 'p')->hasClass('one');                   // false
html5qp($html, 'p')->removeClass('one')->attr('class'); // unchanged

What is the new behavior?

  • These methods split the class attribute on any whitespace, as DOMTraverser::matchClasses() already does
  • find('.one'), hasClass('one') and removeClass('one') handle the class above

Does this introduce a breaking change?

  • Yes
  • No

Other information

Adds DOMQueryTest::testClassMethodsSplitOnAnyWhitespace and a CHANGELOG entry.

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.23%. Comparing base (3872ee0) to head (a78ef9b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #164   +/-   ##
=========================================
  Coverage     91.23%   91.23%           
  Complexity     1441     1441           
=========================================
  Files            26       26           
  Lines          3183     3183           
=========================================
  Hits           2904     2904           
  Misses          279      279           

☔ View full report in Codecov by Harness.
📢 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.

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