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)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: Waldo, Assigned: Waldo)

References

()

Details

(Keywords: dom2)

Attachments

(1 file, 1 obsolete file)

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.
Taking, because this looks fairly easy to fix going by a cursory glance at the code...
Assignee: general → jwalden+bmo
Attached patch Patch (obsolete) — — Splinter Review
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 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-
s/null/0/
Attached patch Patch, v2 — — Splinter Review
(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 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+
Patch checked in, marking FIXED.
Status: NEW → RESOLVED
Closed: 20 years ago
OS: Linux → All
Hardware: PC → All
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9alpha
Flags: in-testsuite+
Component: DOM: Core → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: