From 8fe518719e24bf20dca77182e05b3c391a196fa5 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sun, 22 Feb 2009 15:16:19 -0600 Subject: [PATCH] Fix Selector to match elements with attributes containing hyphens. [#285 state:resolved] (leiyou, jddalton, kangax) --- CHANGELOG | 2 ++ src/dom/selector.js | 2 +- test/unit/fixtures/selector.html | 2 ++ test/unit/selector_test.js | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 2b07457..11c52ca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Fix Selector to match elements with attributes containing hyphens. [#285 state:resolved] (leiyou, jddalton, kangax) + * Make sure Form.reset always returns a reference to the receiver element. [#309 state:resolved] (Phil, kangax) * Escape ":" and "." characters when doing contextual CSS selection in browsers that support querySelectorAll. [#559 state:resolved] (fxtentacle, Andrew Dupont) diff --git a/src/dom/selector.js b/src/dom/selector.js index 331299d..158877c 100644 --- a/src/dom/selector.js +++ b/src/dom/selector.js @@ -340,7 +340,7 @@ Object.extend(Selector, { { name: 'id', re: /^#([\w\-\*]+)(\b|$)/ }, { name: 'className', re: /^\.([\w\-\*]+)(\b|$)/ }, { name: 'pseudo', re: /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/ }, - { name: 'attrPresence', re: /^\[((?:[\w]+:)?[\w]+)\]/ }, + { name: 'attrPresence', re: /^\[((?:[\w-]+:)?[\w]+)\]/ }, { name: 'attr', re: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/ } ], diff --git a/test/unit/fixtures/selector.html b/test/unit/fixtures/selector.html index d745c8f..cad88a6 100644 --- a/test/unit/fixtures/selector.html +++ b/test/unit/fixtures/selector.html @@ -66,4 +66,6 @@
+ +
blah
diff --git a/test/unit/selector_test.js b/test/unit/selector_test.js index 519dd98..c756fbe 100644 --- a/test/unit/selector_test.js +++ b/test/unit/selector_test.js @@ -87,6 +87,10 @@ new Test.Unit.Runner({ this.assertEnumEqual($$('#troubleForm *[type]'), $$('#troubleForm [type]')); }, + testSelectorWithAttributeContainingDash: function() { + this.assertEnumEqual([$('attr_with_dash')], $$('[foo-bar]')); + }, + testSelectorWithUniversalAndHyphenTokenizedAttributeValue: function() { this.assertEnumEqual([$('item_3')], $$('*[xml:lang|="es"]')); this.assertEnumEqual([$('item_3')], $$('*[xml:lang|="ES"]'));