mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Check quirks mode in {Document,Element}::getElementsByClassName
Fixes #4604.
This commit is contained in:
parent
a227faa416
commit
9da761fc64
2 changed files with 14 additions and 8 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[getElementsByClassName-14.htm]
|
||||
type: testharness
|
||||
[document.getElementsByClassName(): case-insensitive (quirks mode)]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue