From 3f8882450c0392a8463568090c541facd6f474b7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 13 Mar 2014 10:35:29 -0700 Subject: [PATCH] script: Fix background color of Acid2. There were two problems here: (1) we did not process style sheets with an unexpected `rel` attribute but a correct MIME type; (2) we did not consider `none` a valid value for the `background` property. --- .../script/html/hubbub_html_parser.rs | 19 ++++++++++------- src/components/style/properties.rs.mako | 1 + src/components/util/str.rs | 13 ++++++++++++ src/test/ref/background_none_a.html | 21 +++++++++++++++++++ src/test/ref/background_none_b.html | 16 ++++++++++++++ src/test/ref/basic.list | 1 + 6 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 src/test/ref/background_none_a.html create mode 100644 src/test/ref/background_none_b.html diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 5e555b63f39..e96c3eaf893 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -22,9 +22,10 @@ use hubbub::hubbub; use servo_msg::constellation_msg::SubpageId; use servo_net::resource_task::{Load, Payload, Done, ResourceTask, load_whole_resource}; use servo_util::namespace::Null; -use servo_util::str::DOMString; +use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS}; use servo_util::task::spawn_named; use servo_util::url::parse_url; +use std::ascii::StrAsciiExt; use std::cast; use std::cell::RefCell; use std::comm::{Port, SharedChan}; @@ -337,12 +338,16 @@ pub fn parse_html(page: &Page, ElementNodeTypeId(HTMLLinkElementTypeId) => { match (element.get().get_attribute(Null, "rel"), element.get().get_attribute(Null, "href")) { - (Some(rel), Some(href)) => { - if "stylesheet" == rel.get().value_ref() { - debug!("found CSS stylesheet: {:s}", href.get().value_ref()); - let url = parse_url(href.get().value_ref(), Some(url2.clone())); - css_chan2.send(CSSTaskNewFile(UrlProvenance(url))); - } + (Some(ref rel), Some(ref href)) if rel.get() + .value_ref() + .split(HTML_SPACE_CHARACTERS. + as_slice()) + .any(|s| { + s.eq_ignore_ascii_case("stylesheet") + }) => { + debug!("found CSS stylesheet: {:s}", href.get().value_ref()); + let url = parse_url(href.get().value_ref(), Some(url2.clone())); + css_chan2.send(CSSTaskNewFile(UrlProvenance(url))); } _ => {} } diff --git a/src/components/style/properties.rs.mako b/src/components/style/properties.rs.mako index a9e4c0b03fd..16a6628c05d 100644 --- a/src/components/style/properties.rs.mako +++ b/src/components/style/properties.rs.mako @@ -499,6 +499,7 @@ pub mod longhands { let image_url = parse_url(url.as_slice(), Some(base_url.clone())); Some(Some(image_url)) }, + &ast::Ident(ref value) if "none" == value.to_ascii_lower() => Some(None), _ => None, } } diff --git a/src/components/util/str.rs b/src/components/util/str.rs index 6010ef69636..bd89ad9ea6f 100644 --- a/src/components/util/str.rs +++ b/src/components/util/str.rs @@ -25,3 +25,16 @@ pub fn is_whitespace(s: &str) -> bool { _ => false }) } + +/// A "space character" according to: +/// +/// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html# +/// space-character +pub static HTML_SPACE_CHARACTERS: [char, ..5] = [ + '\u0020', + '\u0009', + '\u000a', + '\u000c', + '\u000d', +]; + diff --git a/src/test/ref/background_none_a.html b/src/test/ref/background_none_a.html new file mode 100644 index 00000000000..e74c01404c2 --- /dev/null +++ b/src/test/ref/background_none_a.html @@ -0,0 +1,21 @@ + + + +background: none test + + + +
+ + + diff --git a/src/test/ref/background_none_b.html b/src/test/ref/background_none_b.html new file mode 100644 index 00000000000..f6bc5208519 --- /dev/null +++ b/src/test/ref/background_none_b.html @@ -0,0 +1,16 @@ + + + +background: none test + + + +
+ + + diff --git a/src/test/ref/basic.list b/src/test/ref/basic.list index c47a03dd3fb..8108ab7a9c9 100644 --- a/src/test/ref/basic.list +++ b/src/test/ref/basic.list @@ -53,3 +53,4 @@ == position_fixed_static_y_a.html position_fixed_static_y_b.html == position_relative_a.html position_relative_b.html == position_relative_top_percentage_a.html position_relative_top_percentage_b.html +== background_none_a.html background_none_b.html