From 6e745b5a00dfeea1a65d5b02c5bd3e834ad1b79d Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 7 Oct 2015 10:52:44 +0200 Subject: [PATCH] Avoid panicking in the implementation of HTMLOptionElement#text for non-element, non-text children. --- components/script/dom/htmloptionelement.rs | 3 ++- .../the-option-element/option-text-recurse.html | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index 462ba07021d..a300e0ca74e 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -7,6 +7,7 @@ use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods use dom::bindings::codegen::Bindings::HTMLOptionElementBinding; use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; +use dom::bindings::codegen::InheritTypes::ElementDerived; use dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast, HTMLElementCast, NodeCast, TextDerived}; use dom::bindings::codegen::InheritTypes::{HTMLOptionElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived}; @@ -71,7 +72,7 @@ fn collect_text(node: &&Node, value: &mut DOMString) { if child.r().is_text() { let characterdata = CharacterDataCast::to_ref(child.r()).unwrap(); value.push_str(&characterdata.Data()); - } else { + } else if child.is_element() { collect_text(&child.r(), value); } } diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/the-option-element/option-text-recurse.html b/tests/wpt/web-platform-tests/html/semantics/forms/the-option-element/option-text-recurse.html index 46baa8e1ce5..cf854f5260b 100644 --- a/tests/wpt/web-platform-tests/html/semantics/forms/the-option-element/option-text-recurse.html +++ b/tests/wpt/web-platform-tests/html/semantics/forms/the-option-element/option-text-recurse.html @@ -74,4 +74,19 @@ test(function() { option.appendChild(document.createTextNode("text")); assert_equals(option.text, "text"); }, "option.text should work if the option is in a MathML script element"); + +test(function() { + var option = document.createElement("option"); + option.appendChild(document.createTextNode("te")); + option.appendChild(document.createComment("comment")); + option.appendChild(document.createTextNode("xt")); + assert_equals(option.text, "text"); +}, "option.text should ignore comment children"); +test(function() { + var option = document.createElement("option"); + option.appendChild(document.createTextNode("te")); + option.appendChild(document.createProcessingInstruction("target", "data")); + option.appendChild(document.createTextNode("xt")); + assert_equals(option.text, "text"); +}, "option.text should ignore PI children");