Repository navigation
Return '' from tag() when the first match is not an element - #101
Merged
Merged
Conversation
tag() warns and returns NULL when the first match is not an element
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
force-pushed
the
fix/issue-93
branch
from
October 25, 2026 23:36
04715cf to
86f107c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #93
tag()read->tagNameon the first match without checking its type, so whencontents()put a text, comment or processing-instruction node first it warned "Undefined property: DOMText::$tagName" and returnedNULL. It now returns''for a non-element first match, the same as for an empty match set.I chose
''overnodeName(#text,#comment), which callers could mistake for a tag name, and over skipping ahead to the first element, which would quietly change which nodetag()describes.Tests:
testTag()now also covers an empty set.testTagFirstMatchOfContentscovers text-, comment-, PI- and element-first sets. The non-element cases fail onmain.The same class of bug in
attr(),addClass()and the other attribute and class methods is tracked in #98.🤖 Generated with Claude Code