Skip to content
Permalink
Browse files

Insert and lookup element selectors case-insensitively.

Both the insertion key for rules having a LocalNameSelector and the lookup-key sent in
get_all_matching_rules should be ASCII lower case.
  • Loading branch information...
pradeep90 authored and pcwalton committed Nov 6, 2013
1 parent c490329 commit 315352c3c5d2f0edbe09f506f9f76fec5a3aa485
Showing with 13 additions and 3 deletions.
  1. +13 −3 src/components/style/selector_matching.rs
@@ -42,6 +42,7 @@ pub enum StylesheetOrigin {
/// element name, etc. will contain the Rules that actually match that
/// node.
pub struct SelectorMap {
// TODO: Tune the initial capacity of the HashMap
// FIXME: Use interned strings
priv id_hash: HashMap<~str, ~[Rule]>,
priv class_hash: HashMap<~str, ~[Rule]>,
@@ -88,7 +89,10 @@ impl SelectorMap {
}

rules_list.push_all_move(SelectorMap::get_matching_rules_from_hash(
node, pseudo_element, &self.element_hash, element.get_local_name()));
node, pseudo_element, &self.element_hash,
// HTML elements in HTML documents must be matched case-insensitively
// TODO: case-sensitivity depends on the document type
element.get_local_name().to_ascii_lower()));
rules_list.push_all_move(SelectorMap::get_matching_rules(node, pseudo_element,
self.universal_rules));
}
@@ -166,6 +170,7 @@ impl SelectorMap {
let simple_selector_sequence = &selector.compound_selectors.simple_selectors;
for ss in simple_selector_sequence.iter() {
match *ss {
// TODO: Implement case-sensitivity based on the document type and quirks mode
IDSelector(ref id) => return Some(id.clone()),
_ => {}
}
@@ -178,6 +183,7 @@ impl SelectorMap {
let simple_selector_sequence = &rule.selector.compound_selectors.simple_selectors;
for ss in simple_selector_sequence.iter() {
match *ss {
// TODO: Implement case-sensitivity based on the document type and quirks mode
ClassSelector(ref class) => return Some(class.clone()),
_ => {}
}
@@ -190,7 +196,9 @@ impl SelectorMap {
let simple_selector_sequence = &rule.selector.compound_selectors.simple_selectors;
for ss in simple_selector_sequence.iter() {
match *ss {
LocalNameSelector(ref name) => return Some(name.clone()),
// HTML elements in HTML documents must be matched case-insensitively
// TODO: case-sensitivity depends on the document type
LocalNameSelector(ref name) => return Some(name.to_ascii_lower()),
_ => {}
}
}
@@ -553,9 +561,11 @@ fn test_get_class_name(){

#[test]
fn test_get_element_name(){
let rules_list = get_mock_rules(["img.foo", "#top"]);
let rules_list = get_mock_rules(["img.foo", "#top", "IMG", "ImG"]);
assert_eq!(SelectorMap::get_element_name(rules_list[0][0].clone()), Some(~"img"));
assert_eq!(SelectorMap::get_element_name(rules_list[1][0].clone()), None);
assert_eq!(SelectorMap::get_element_name(rules_list[2][0].clone()), Some(~"img"));
assert_eq!(SelectorMap::get_element_name(rules_list[3][0].clone()), Some(~"img"));
}

#[test]

0 comments on commit 315352c

Please sign in to comment.
You can’t perform that action at this time.