Skip to content

Commit

Permalink
Fix: whitespace is considered as spaces(U+0020), tabs(U+0009), and li…
Browse files Browse the repository at this point in the history
…ne breaks(U+000D U+000A)
  • Loading branch information
june0cho committed Feb 21, 2014
1 parent 327e1e2 commit ab58940
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/main/layout/box_.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/main/layout/construct.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 5 additions & 2 deletions src/components/util/str.rs
Expand Up @@ -19,6 +19,9 @@ 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')
pub fn is_whitespace(s: &str) -> bool {
s.chars().all(|c| match c {
'\u0020' | '\u0009' | '\u000D' | '\u000A' => true,
_ => false
})
}

5 comments on commit ab58940

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at june0cho@ab58940

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging june0cho/servo/whitespace_nbsp = ab58940 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

june0cho/servo/whitespace_nbsp = ab58940 merged ok, testing candidate = 013010d

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 013010d

Please sign in to comment.