Skip to content

Commit

Permalink
Prevent '&nbsp' from stripping as whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
june0cho committed Feb 21, 2014
1 parent 65191b0 commit 327e1e2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/main/layout/box_.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/main/layout/construct.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/util/str.rs
Expand Up @@ -19,3 +19,6 @@ pub fn null_str_as_empty_ref<'a>(s: &'a Option<DOMString>) -> &'a str {
}
}

pub fn is_whitespace_not_nbsp(s: &str) -> bool {
s.chars().all(|c| c.is_whitespace() && c != '\xa0')
}

0 comments on commit 327e1e2

Please sign in to comment.