Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle properly alternate stylesheet #14911

Merged
merged 3 commits into from Jan 11, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -99,6 +99,17 @@ impl HTMLLinkElement {
})
})
}

pub fn is_alternate(&self) -> bool {
let rel = get_attr(self.upcast(), &local_name!("rel"));
match rel {
Some(ref value) => {
value.split(HTML_SPACE_CHARACTERS)
.any(|s| s.eq_ignore_ascii_case("alternate"))
},
None => false,
}
}
}

fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
@@ -112,17 +123,8 @@ fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
fn string_is_stylesheet(value: &Option<String>) -> bool {
match *value {
Some(ref value) => {
let mut found_stylesheet = false;
for s in value.split(HTML_SPACE_CHARACTERS).into_iter() {
if s.eq_ignore_ascii_case("alternate") {
return false;
}

if s.eq_ignore_ascii_case("stylesheet") {
found_stylesheet = true;
}
}
found_stylesheet
value.split(HTML_SPACE_CHARACTERS)
.any(|s| s.eq_ignore_ascii_case("stylesheet"))
},
None => false,
}
@@ -138,6 +138,9 @@ impl FetchResponseListener for StylesheetContext {
Some(&loader),
win.css_error_reporter(),
ParserContextExtraData::default()));
if elem.downcast::<HTMLLinkElement>().unwrap().is_alternate() {
sheet.set_disabled(true);
}
elem.downcast::<HTMLLinkElement>()
.unwrap()
.set_stylesheet(sheet.clone());
@@ -1,14 +1,11 @@
[subresource-integrity.sub.html]
type: testharness
expected: TIMEOUT
expected: OK
[Style: <crossorigin='anonymous'> with correct hash, ACAO: *]
expected: FAIL

[Style: Same-origin with correct sha256 and sha512 hash, rel='alternate stylesheet' enabled]
expected: NOTRUN

[Style: Same-origin with incorrect sha256 and sha512 hash, rel='alternate stylesheet' enabled]
expected: NOTRUN
expected: FAIL

[Style: Same-origin with incorrect hash.]
expected: FAIL
@@ -0,0 +1,3 @@
body {
background-color: black;
}
@@ -1,3 +1,5 @@
@import url("alternate-import.css");

div {
background-color: red;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.