diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-06-07 19:00:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-07 19:00:54 -0700 |
commit | ad47d33511c318fe208158bb16deb5086979e0c7 (patch) | |
tree | d2057957e2bb00cbfc236b0a4fa5dbbfe664f230 /components/script/dom | |
parent | 1ea4a44fad4dfd6d7ca1152e06cf07b7e927951b (diff) | |
parent | 18d847227c82ca552099e53606aa846cc873df5d (diff) | |
download | servo-ad47d33511c318fe208158bb16deb5086979e0c7.tar.gz servo-ad47d33511c318fe208158bb16deb5086979e0c7.zip |
Auto merge of #17206 - heycam:lang-snapshots, r=emilio
match :lang() against snapshots correctly
Reviewed in https://bugzilla.mozilla.org/show_bug.cgi?id=1365162.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17206)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/str.rs | 57 | ||||
-rw-r--r-- | components/script/dom/element.rs | 9 |
2 files changed, 6 insertions, 60 deletions
diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 6cb17fae4e3..4e579044491 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -113,63 +113,6 @@ pub fn is_token(s: &[u8]) -> bool { }) } -/// Returns whether the language is matched, as defined by -/// [RFC 4647](https://tools.ietf.org/html/rfc4647#section-3.3.2). -pub fn extended_filtering(tag: &str, range: &str) -> bool { - let lang_ranges: Vec<&str> = range.split(',').collect(); - - lang_ranges.iter().any(|&lang_range| { - // step 1 - let range_subtags: Vec<&str> = lang_range.split('\x2d').collect(); - let tag_subtags: Vec<&str> = tag.split('\x2d').collect(); - - let mut range_iter = range_subtags.iter(); - let mut tag_iter = tag_subtags.iter(); - - // step 2 - // Note: [Level-4 spec](https://drafts.csswg.org/selectors/#lang-pseudo) check for wild card - if let (Some(range_subtag), Some(tag_subtag)) = (range_iter.next(), tag_iter.next()) { - if !(range_subtag.eq_ignore_ascii_case(tag_subtag) || range_subtag.eq_ignore_ascii_case("*")) { - return false; - } - } - - let mut current_tag_subtag = tag_iter.next(); - - // step 3 - for range_subtag in range_iter { - // step 3a - if range_subtag.eq_ignore_ascii_case("*") { - continue; - } - match current_tag_subtag.clone() { - Some(tag_subtag) => { - // step 3c - if range_subtag.eq_ignore_ascii_case(tag_subtag) { - current_tag_subtag = tag_iter.next(); - continue; - } else { - // step 3d - if tag_subtag.len() == 1 { - return false; - } else { - // else step 3e - continue with loop - current_tag_subtag = tag_iter.next(); - if current_tag_subtag.is_none() { - return false; - } - } - } - }, - // step 3b - None => { return false; } - } - } - // step 4 - true - }) -} - /// A DOMString. /// diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index c0d4b6b700a..cb882f53463 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -26,7 +26,7 @@ use dom::bindings::js::{JS, LayoutJS, MutNullableJS}; use dom::bindings::js::{Root, RootedReference}; use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::reflector::DomObject; -use dom::bindings::str::{DOMString, extended_filtering}; +use dom::bindings::str::DOMString; use dom::bindings::xmlname::{namespace_from_domstring, validate_and_extract, xml_name_type}; use dom::bindings::xmlname::XMLName::InvalidXMLName; use dom::characterdata::CharacterData; @@ -106,6 +106,7 @@ use style::properties::longhands::{self, background_image, border_spacing, font_ use style::restyle_hints::RestyleHint; use style::rule_tree::CascadeLevel; use style::selector_parser::{NonTSPseudoClass, PseudoElement, RestyleDamage, SelectorImpl, SelectorParser}; +use style::selector_parser::extended_filtering; use style::shared_lock::{SharedRwLock, Locked}; use style::sink::Push; use style::stylearc::Arc; @@ -2464,8 +2465,10 @@ impl<'a> ::selectors::Element for Root<Element> { .map_or(false, |attr| attr.value().eq(expected_value)) } - // FIXME(#15746): This is wrong, we need to instead use extended filtering as per RFC4647 - // https://tools.ietf.org/html/rfc4647#section-3.3.2 + // FIXME(heycam): This is wrong, since extended_filtering accepts + // a string containing commas (separating each language tag in + // a list) but the pseudo-class instead should be parsing and + // storing separate <ident> or <string>s for each language tag. NonTSPseudoClass::Lang(ref lang) => extended_filtering(&*self.get_lang(), &*lang), NonTSPseudoClass::ReadOnly => |