diff --git a/CHANGELOG b/CHANGELOG index 2b07457c9..11c52ca11 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 331299dc8..158877c12 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 d745c8fd5..cad88a69d 100644 --- a/test/unit/fixtures/selector.html +++ b/test/unit/fixtures/selector.html @@ -66,4 +66,6 @@

Some title here

+ +
blah
diff --git a/test/unit/selector_test.js b/test/unit/selector_test.js index 519dd989e..c756fbe25 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"]'));