Closed
Bug 345666
Opened 20 years ago
Closed 20 years ago
Node.normalize() doesn't remove empty Text nodes
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla1.9alpha1
People
(Reporter: Waldo, Assigned: Waldo)
References
(
URL
)
Details
(Keywords: dom2)
Attachments
(1 file, 1 obsolete file)
|
6.56 KB,
patch
|
jst
:
review+
jst
:
superreview+
|
Details | Diff | Splinter Review |
Normalization of an element containing only an empty text node doesn't remove that text node. According to the DOM Level 3 specification, "there are neither adjacent Text nodes nor empty Text nodes" in a node which has been normalized.
http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-normalize
The DOM Level 1 spec does not include empty Text nodes in its description of Node.normalize(), and that addition was made for DOM Level 2. This wouldn't strictly be a backwards-compatible change, but I suspect no one relies on that behavior, and implementations such as Sun's Java 1.5 obey the newer spec.
| Assignee | ||
Comment 1•20 years ago
|
||
Taking, because this looks fairly easy to fix going by a cursory glance at the code...
Assignee: general → jwalden+bmo
| Assignee | ||
Comment 2•20 years ago
|
||
Also, for what it's worth, Safari and Opera both remove empty Text nodes during normalization.
Attachment #230678 -
Flags: superreview?(jst)
Attachment #230678 -
Flags: review?(jst)
Comment 3•20 years ago
|
||
Comment on attachment 230678 [details] [diff] [review]
Patch
case nsIDOMNode::TEXT_NODE:
+ // ensure that if the text node is empty, it is removed
+ {
+ nsAutoString text;
+ result = node->GetNodeValue(text);
+ if (NS_FAILED(result)) {
+ return result;
+ }
+
+ if (text.IsEmpty()) {
This should just QI to nsIContent and check if TextLength() returns null or not, that'd be *much* cheaper than copying the string data out of every text node while walking the tree.
r/sr- based on that, but other than that this looks good.
Attachment #230678 -
Flags: superreview?(jst)
Attachment #230678 -
Flags: superreview-
Attachment #230678 -
Flags: review?(jst)
Attachment #230678 -
Flags: review-
Comment 4•20 years ago
|
||
s/null/0/
| Assignee | ||
Comment 5•20 years ago
|
||
(In reply to comment #3)
> that'd be *much* cheaper than copying the string data out of every text
> node while walking the tree.
Mm, internal APIs...thanks for pointing out the ridiculously more efficient method that uses them. :-)
Attachment #230678 -
Attachment is obsolete: true
Attachment #230690 -
Flags: superreview?(jst)
Attachment #230690 -
Flags: review?(jst)
Comment 6•20 years ago
|
||
Comment on attachment 230690 [details] [diff] [review]
Patch, v2
r+sr=jst
Attachment #230690 -
Flags: superreview?(jst)
Attachment #230690 -
Flags: superreview+
Attachment #230690 -
Flags: review?(jst)
Attachment #230690 -
Flags: review+
| Assignee | ||
Comment 7•20 years ago
|
||
Patch checked in, marking FIXED.
Status: NEW → RESOLVED
Closed: 20 years ago
OS: Linux → All
Hardware: PC → All
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9alpha
| Assignee | ||
Updated•20 years ago
|
Flags: in-testsuite+
You need to log in
before you can comment on or make changes to this bug.
Description
•