From d6b843c9cbe65f2cb83efe109e780e8dfd1a4755 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Mon, 5 Nov 2007 17:43:56 +0000 Subject: [PATCH] Ensure Element#hasClassName always returns a boolean. Closes #10075. --- CHANGELOG | 2 ++ src/dom.js | 2 +- test/unit/dom.html | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d9690d1..da9a811 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Ensure Element#hasClassName always returns a boolean. Closes #10075. [ronnylovtangen, Tobie Langel] + * Ensure selectors of the form "[href]" (attribute token with no preceding tag name) work properly. Closes #8870. [chao, kangax, Andrew Dupont] * Performance optimizations for Element#descendantOf. Costliness should no longer be dependent on the difference in depth between the parent and the child. [Andrew Dupont] diff --git a/src/dom.js b/src/dom.js index 086cf71..f2367f4 100644 --- a/src/dom.js +++ b/src/dom.js @@ -316,7 +316,7 @@ Element.Methods = { if (!(element = $(element))) return; var elementClassName = element.className; return (elementClassName.length > 0 && (elementClassName == className || - elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))); + new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName))); }, addClassName: function(element, className) { diff --git a/test/unit/dom.html b/test/unit/dom.html index 1ed5565..59d7897 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -1403,12 +1403,12 @@ }}, testHasClassName: function() {with(this) { - assert(!$('class_names').hasClassName('does_not_exist')); - assert($('class_names').down().hasClassName('A')); - assert(!$('class_names').down().hasClassName('does_not_exist')); - assert($('class_names_ul').hasClassName('A')); - assert($('class_names_ul').hasClassName('B')); - assert(!$('class_names_ul').hasClassName('does_not_exist')); + assertIdentical(false, $('class_names').hasClassName('does_not_exist')); + assertIdentical(true, $('class_names').down().hasClassName('A')); + assertIdentical(false, $('class_names').down().hasClassName('does_not_exist')); + assertIdentical(true, $('class_names_ul').hasClassName('A')); + assertIdentical(true, $('class_names_ul').hasClassName('B')); + assertIdentical(false, $('class_names_ul').hasClassName('does_not_exist')); }}, testAddClassName: function() {with(this) {