Skip to content

Return '' from tag() when the first match is not an element - #101

Merged
gravitypdf-bot merged 1 commit into
mainfrom
fix/issue-93
Oct 25, 2026
Merged

gravitypdf-bot merged 1 commit into
mainfrom
fix/issue-93

Conversation

@gravitypdf-bot

Copy link
Copy Markdown
Contributor

Fixes #93

tag() read ->tagName on the first match without checking its type, so when contents() put a text, comment or processing-instruction node first it warned "Undefined property: DOMText::$tagName" and returned NULL. It now returns '' for a non-element first match, the same as for an empty match set.

I chose '' over nodeName (#text, #comment), which callers could mistake for a tag name, and over skipping ahead to the first element, which would quietly change which node tag() describes.

Tests: testTag() now also covers an empty set. testTagFirstMatchOfContents covers text-, comment-, PI- and element-first sets. The non-element cases fail on main.

The same class of bug in attr(), addClass() and the other attribute and class methods is tracked in #98.

🤖 Generated with Claude Code

@gravitypdf-bot gravitypdf-bot changed the title tag() warns and returns NULL when the first match is not an element Return '' from tag() when the first match is not an element Oct 25, 2026
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.32%. Comparing base (bfa4f43) to head (86f107c).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #101   +/-   ##
=========================================
  Coverage     90.32%   90.32%           
- Complexity     1429     1430    +1     
=========================================
  Files            25       25           
  Lines          3184     3185    +1     
=========================================
+ Hits           2876     2877    +1     
  Misses          308      308           

☔ 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.

tag() read tagName on whatever node came first, so a text, comment or
processing instruction node from contents() raised an "Undefined
property" warning and returned NULL. Return an empty string instead,
matching the empty match set. Fixes #93.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gravitypdf-bot
gravitypdf-bot merged commit f850652 into main Oct 25, 2026
12 checks passed
@gravitypdf-bot
gravitypdf-bot deleted the fix/issue-93 branch October 25, 2026 23:37
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.

tag() warns and returns NULL when the first match is not an element

2 participants