mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
Avoid panicking in the implementation of HTMLOptionElement#text for non-element, non-text children.
This commit is contained in:
parent
409fbafe9c
commit
6e745b5a00
2 changed files with 17 additions and 1 deletions
|
@ -7,6 +7,7 @@ use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods
|
||||||
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
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::{CharacterDataCast, ElementCast, HTMLElementCast, NodeCast, TextDerived};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLOptionElementDerived};
|
use dom::bindings::codegen::InheritTypes::{HTMLOptionElementDerived};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived};
|
use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived};
|
||||||
|
@ -71,7 +72,7 @@ fn collect_text(node: &&Node, value: &mut DOMString) {
|
||||||
if child.r().is_text() {
|
if child.r().is_text() {
|
||||||
let characterdata = CharacterDataCast::to_ref(child.r()).unwrap();
|
let characterdata = CharacterDataCast::to_ref(child.r()).unwrap();
|
||||||
value.push_str(&characterdata.Data());
|
value.push_str(&characterdata.Data());
|
||||||
} else {
|
} else if child.is_element() {
|
||||||
collect_text(&child.r(), value);
|
collect_text(&child.r(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,4 +74,19 @@ test(function() {
|
||||||
option.appendChild(document.createTextNode("text"));
|
option.appendChild(document.createTextNode("text"));
|
||||||
assert_equals(option.text, "text");
|
assert_equals(option.text, "text");
|
||||||
}, "option.text should work if the option is in a MathML script element");
|
}, "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");
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue