From 594df4d696be81debe30c4b95a4db3fde17213e1 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 3 Apr 2014 11:08:17 -0400 Subject: [PATCH 1/4] Implement split_html_space_chars helper function --- src/components/util/str.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/util/str.rs b/src/components/util/str.rs index cdbf1bb9ea9..abd5984b8ef 100644 --- a/src/components/util/str.rs +++ b/src/components/util/str.rs @@ -2,7 +2,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use std::iter::Filter; +use std::str::CharSplits; + pub type DOMString = ~str; +pub type StaticCharVec = &'static [char]; pub type StaticStringVec = &'static [&'static str]; pub fn null_str_as_empty(s: &Option) -> DOMString { @@ -31,7 +35,7 @@ pub fn is_whitespace(s: &str) -> bool { /// /// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html# /// space-character -pub static HTML_SPACE_CHARACTERS: [char, ..5] = [ +pub static HTML_SPACE_CHARACTERS: StaticCharVec = &[ '\u0020', '\u0009', '\u000a', @@ -39,3 +43,6 @@ pub static HTML_SPACE_CHARACTERS: [char, ..5] = [ '\u000d', ]; +pub fn split_html_space_chars<'a>(s: &'a str) -> Filter<'a, &'a str, CharSplits<'a, StaticCharVec>> { + s.split(HTML_SPACE_CHARACTERS).filter(|&split| !split.is_empty()) +} From 943743195fc68e56968d545829d9ddd43b0ee601 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 3 Apr 2014 12:11:03 -0400 Subject: [PATCH 2/4] Split class names using split_html_space_chars helper function --- src/components/script/dom/element.rs | 5 ++--- src/components/script/dom/htmlcollection.rs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index aa092bce325..c384fdca8ce 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -29,7 +29,7 @@ use layout_interface::{MatchSelectorsDocumentDamage}; use style; use servo_util::namespace; use servo_util::namespace::{Namespace, Null}; -use servo_util::str::{DOMString, null_str_as_empty_ref}; +use servo_util::str::{DOMString, null_str_as_empty_ref, split_html_space_chars}; use std::ascii::StrAsciiExt; use std::cast; @@ -376,9 +376,8 @@ impl AttributeHandlers for JS { } fn has_class(&self, name: &str) -> bool { - // FIXME: https://github.com/mozilla/servo/issues/1840 let class_names = self.get_string_attribute("class"); - let mut classes = class_names.split(' '); + let mut classes = split_html_space_chars(class_names); classes.any(|class| name == class) } diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index eb56ebac542..e88aedd02db 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -10,7 +10,7 @@ use dom::element::{Element, AttributeHandlers}; use dom::node::{Node, NodeHelpers}; use dom::window::Window; use servo_util::namespace::Namespace; -use servo_util::str::DOMString; +use servo_util::str::{DOMString, split_html_space_chars}; use serialize::{Encoder, Encodable}; @@ -100,7 +100,7 @@ impl HTMLCollection { } } let filter = ClassNameFilter { - classes: classes.split(' ').map(|class| class.into_owned()).to_owned_vec() + classes: split_html_space_chars(classes).map(|class| class.into_owned()).to_owned_vec() }; HTMLCollection::create(window, root, ~filter) } From 0b24ef4cf8eaed629484eaf55ff8b5f853541300 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 3 Apr 2014 12:28:37 -0400 Subject: [PATCH 3/4] Added HTML space characters check content test --- src/test/content/test_htmlspacechars.html | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/content/test_htmlspacechars.html diff --git a/src/test/content/test_htmlspacechars.html b/src/test/content/test_htmlspacechars.html new file mode 100644 index 00000000000..dc9166f48b2 --- /dev/null +++ b/src/test/content/test_htmlspacechars.html @@ -0,0 +1,27 @@ + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ + From c451b1c9dc31e91381f10d0cadd1d1377162367f Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 3 Apr 2014 18:05:10 -0400 Subject: [PATCH 4/4] Adding .DS_Store to list of ignored files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a493c807153..054b1488743 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.pyc *.swp *.swo +.DS_Store servo-test Makefile Servo.app