Skip to content
Permalink
Browse files

Check quirks mode in {Document,Element}::getElementsByClassName

Fixes #4604.
  • Loading branch information
brunoabinader committed Jan 12, 2015
1 parent a227faa commit 9da761fc64a31b7a45fa21fad0fd43669366dcc2
Showing with 14 additions and 8 deletions.
  1. +14 −3 components/script/dom/element.rs
  2. +0 −5 tests/wpt/metadata/dom/nodes/getElementsByClassName-14.htm.ini
@@ -55,6 +55,8 @@ use style::{IntegerAttribute, LengthAttribute, ParserContext, matches};
use servo_util::namespace;
use servo_util::str::{DOMString, LengthOrPercentageOrAuto};

use html5ever::tree_builder::{NoQuirks, LimitedQuirks, Quirks};

use cssparser::RGBA;
use std::ascii::AsciiExt;
use std::cell::{Ref, RefMut};
@@ -571,7 +573,7 @@ pub trait AttributeHandlers {
value: DOMString) -> AttrValue;

fn remove_attribute(self, namespace: Namespace, name: &str);
fn has_class(&self, name: &Atom) -> bool;
fn has_class(self, name: &Atom) -> bool;

fn set_atomic_attribute(self, name: &Atom, value: DOMString);

@@ -713,10 +715,19 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
};
}

fn has_class(&self, name: &Atom) -> bool {
fn has_class(self, name: &Atom) -> bool {
let quirks_mode = {
let node: JSRef<Node> = NodeCast::from_ref(self);
let owner_doc = node.owner_doc().root();
owner_doc.r().quirks_mode()
};
let is_equal = |lhs: &Atom, rhs: &Atom| match quirks_mode {
NoQuirks | LimitedQuirks => lhs == rhs,
Quirks => lhs.as_slice().eq_ignore_ascii_case(rhs.as_slice())
};
self.get_attribute(ns!(""), &atom!("class")).root().map(|attr| {
attr.r().value().tokens().map(|tokens| {
tokens.iter().any(|atom| atom == name)
tokens.iter().any(|atom| is_equal(name, atom))
}).unwrap_or(false)
}).unwrap_or(false)
}

This file was deleted.

5 comments on commit 9da761f

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Jan 12, 2015

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Jan 12, 2015

merging brunoabinader/servo/getElementsByClassName-quirksMode = 9da761f into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Jan 12, 2015

brunoabinader/servo/getElementsByClassName-quirksMode = 9da761f merged ok, testing candidate = 151343c

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Jan 12, 2015

fast-forwarding master to auto = 151343c

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