From 327e1e20a91fe1849ab84a2f0e710e3d4d94aba4 Mon Sep 17 00:00:00 2001 From: Junyoung Cho Date: Fri, 21 Feb 2014 16:16:06 +0900 Subject: [PATCH 1/2] Prevent ' ' from stripping as whitespace --- src/components/main/layout/box_.rs | 3 ++- src/components/main/layout/construct.rs | 6 ++---- src/components/util/str.rs | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index d4f16e1e37a..3350e3050f8 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -22,6 +22,7 @@ use servo_util::geometry::Au; use servo_util::geometry; use servo_util::range::*; use servo_util::namespace; +use servo_util::str::is_whitespace_not_nbsp; use std::cast; use std::cell::RefCell; @@ -1428,7 +1429,7 @@ impl Box { /// Returns true if this box is an unscanned text box that consists entirely of whitespace. pub fn is_whitespace_only(&self) -> bool { match self.specific { - UnscannedTextBox(ref text_box_info) => text_box_info.text.is_whitespace(), + UnscannedTextBox(ref text_box_info) => is_whitespace_not_nbsp(text_box_info.text), _ => false, } } diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index 98d33db8d26..4a2dc5a055d 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -43,6 +43,7 @@ use style::ComputedValues; use servo_util::namespace; use servo_util::url::parse_url; use servo_util::url::is_image_data; +use servo_util::str::is_whitespace_not_nbsp; use extra::url::Url; use extra::arc::Arc; @@ -724,10 +725,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> { match self.type_id() { TextNodeTypeId => { unsafe { - if !self.with_text(|text| text.characterdata - .data - .chars() - .all(|c| c.is_whitespace())) { + if !self.with_text(|text| is_whitespace_not_nbsp(text.characterdata.data)) { return false } diff --git a/src/components/util/str.rs b/src/components/util/str.rs index 13272d8ec42..0b9bd74f074 100644 --- a/src/components/util/str.rs +++ b/src/components/util/str.rs @@ -19,3 +19,6 @@ pub fn null_str_as_empty_ref<'a>(s: &'a Option) -> &'a str { } } +pub fn is_whitespace_not_nbsp(s: &str) -> bool { + s.chars().all(|c| c.is_whitespace() && c != '\xa0') +} From ab589403ed5c6c5f3c5e8d0c28bb5cb15f738f4b Mon Sep 17 00:00:00 2001 From: Junyoung Cho Date: Fri, 21 Feb 2014 21:20:48 +0900 Subject: [PATCH 2/2] Fix: whitespace is considered as spaces(U+0020), tabs(U+0009), and line breaks(U+000D U+000A) --- src/components/main/layout/box_.rs | 4 ++-- src/components/main/layout/construct.rs | 4 ++-- src/components/util/str.rs | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 3350e3050f8..f528a71260d 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -22,7 +22,7 @@ use servo_util::geometry::Au; use servo_util::geometry; use servo_util::range::*; use servo_util::namespace; -use servo_util::str::is_whitespace_not_nbsp; +use servo_util::str::is_whitespace; use std::cast; use std::cell::RefCell; @@ -1429,7 +1429,7 @@ impl Box { /// Returns true if this box is an unscanned text box that consists entirely of whitespace. pub fn is_whitespace_only(&self) -> bool { match self.specific { - UnscannedTextBox(ref text_box_info) => is_whitespace_not_nbsp(text_box_info.text), + UnscannedTextBox(ref text_box_info) => is_whitespace(text_box_info.text), _ => false, } } diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index 4a2dc5a055d..41b38577599 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -43,7 +43,7 @@ use style::ComputedValues; use servo_util::namespace; use servo_util::url::parse_url; use servo_util::url::is_image_data; -use servo_util::str::is_whitespace_not_nbsp; +use servo_util::str::is_whitespace; use extra::url::Url; use extra::arc::Arc; @@ -725,7 +725,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> { match self.type_id() { TextNodeTypeId => { unsafe { - if !self.with_text(|text| is_whitespace_not_nbsp(text.characterdata.data)) { + if !self.with_text(|text| is_whitespace(text.characterdata.data)) { return false } diff --git a/src/components/util/str.rs b/src/components/util/str.rs index 0b9bd74f074..6010ef69636 100644 --- a/src/components/util/str.rs +++ b/src/components/util/str.rs @@ -19,6 +19,9 @@ pub fn null_str_as_empty_ref<'a>(s: &'a Option) -> &'a str { } } -pub fn is_whitespace_not_nbsp(s: &str) -> bool { - s.chars().all(|c| c.is_whitespace() && c != '\xa0') +pub fn is_whitespace(s: &str) -> bool { + s.chars().all(|c| match c { + '\u0020' | '\u0009' | '\u000D' | '\u000A' => true, + _ => false + }) }