mirror of
https://github.com/servo/servo.git
synced 2025-06-26 01:54:33 +01:00
script Exclude CDATASection
nodes from Node::normalize()
(#37550)
Exclude CDATASection nodes from Node::normalize. I made it under the assumption that CDATAs can't have children so we don't need to go into the `else node.Normalize()` branch on line 3485 with them, hope this is correct. Testing: covered by `dom/nodes/Node-normalize.html` Fixes: https://github.com/servo/servo/issues/37006 --------- Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
This commit is contained in:
parent
06b5422abf
commit
3a54ddd034
3 changed files with 9 additions and 9 deletions
|
@ -50,6 +50,7 @@ use style::stylesheets::{Stylesheet, UrlExtraData};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use xml5ever::{local_name, serialize as xml_serialize};
|
use xml5ever::{local_name, serialize as xml_serialize};
|
||||||
|
|
||||||
|
use super::types::CDATASection;
|
||||||
use crate::conversions::Convert;
|
use crate::conversions::Convert;
|
||||||
use crate::document_loader::DocumentLoader;
|
use crate::document_loader::DocumentLoader;
|
||||||
use crate::dom::attr::Attr;
|
use crate::dom::attr::Attr;
|
||||||
|
@ -3458,16 +3459,18 @@ impl NodeMethods<crate::DomTypeHolder> for Node {
|
||||||
let mut children = self.children().enumerate().peekable();
|
let mut children = self.children().enumerate().peekable();
|
||||||
while let Some((_, node)) = children.next() {
|
while let Some((_, node)) = children.next() {
|
||||||
if let Some(text) = node.downcast::<Text>() {
|
if let Some(text) = node.downcast::<Text>() {
|
||||||
|
if text.is::<CDATASection>() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let cdata = text.upcast::<CharacterData>();
|
let cdata = text.upcast::<CharacterData>();
|
||||||
let mut length = cdata.Length();
|
let mut length = cdata.Length();
|
||||||
if length == 0 {
|
if length == 0 {
|
||||||
Node::remove(&node, self, SuppressObserver::Unsuppressed, can_gc);
|
Node::remove(&node, self, SuppressObserver::Unsuppressed, can_gc);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
while children
|
while children.peek().is_some_and(|(_, sibling)| {
|
||||||
.peek()
|
sibling.is::<Text>() && !sibling.is::<CDATASection>()
|
||||||
.is_some_and(|(_, sibling)| sibling.is::<Text>())
|
}) {
|
||||||
{
|
|
||||||
let (index, sibling) = children.next().unwrap();
|
let (index, sibling) = children.next().unwrap();
|
||||||
sibling
|
sibling
|
||||||
.ranges()
|
.ranges()
|
||||||
|
|
|
@ -1260,7 +1260,7 @@ impl WeakRangeVec {
|
||||||
.extend(ranges.drain(..));
|
.extend(ranges.drain(..));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used for steps 7.1-2. when normalizing a node.
|
/// Used for steps 6.1-2. when normalizing a node.
|
||||||
/// <https://dom.spec.whatwg.org/#dom-node-normalize>
|
/// <https://dom.spec.whatwg.org/#dom-node-normalize>
|
||||||
pub(crate) fn drain_to_preceding_text_sibling(&self, node: &Node, sibling: &Node, length: u32) {
|
pub(crate) fn drain_to_preceding_text_sibling(&self, node: &Node, sibling: &Node, length: u32) {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
|
@ -1287,7 +1287,7 @@ impl WeakRangeVec {
|
||||||
sibling.ranges().cell.borrow_mut().extend(ranges.drain(..));
|
sibling.ranges().cell.borrow_mut().extend(ranges.drain(..));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used for steps 7.3-4. when normalizing a node.
|
/// Used for steps 6.3-4. when normalizing a node.
|
||||||
/// <https://dom.spec.whatwg.org/#dom-node-normalize>
|
/// <https://dom.spec.whatwg.org/#dom-node-normalize>
|
||||||
pub(crate) fn move_to_text_child_at(
|
pub(crate) fn move_to_text_child_at(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[Node-normalize.html]
|
|
||||||
[Non-text nodes with empty textContent values.]
|
|
||||||
expected: FAIL
|
|
Loading…
Add table
Add a link
Reference in a new issue