Skip to content

Commit

Permalink
Proper fix (and unit tests) for selector escaping issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Jul 17, 2009
1 parent f4570f3 commit 059ce21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dom/selector.js
Expand Up @@ -170,7 +170,7 @@ var Selector = Class.create({
if (root !== document) {
var oldId = root.id, id = $(root).identify();
// Escape special characters in the ID.
id = id.replace(/[\.:]/g, "\\$1");
id = id.replace(/([\.:])/g, "\\$1");
e = "#" + id + " " + e;
}

Expand Down
11 changes: 11 additions & 0 deletions test/unit/fixtures/selector.html
Expand Up @@ -53,6 +53,17 @@ <h1 class="title">Some title <span>here</span></h1>
</span>
</span>
</div> <!-- #dupContainer -->
<div id="dupContainer.withdot:active">
<span id="dupL1_dotcolon" class="span_foo span_bar">
<span id="dupL2_dotcolon">
<span id="dupL3_dotcolon">
<span id="dupL4_dotcolon">
<span id="dupL5_dotcolon"></span>
</span>
</span>
</span>
</span>
</div> <!-- #dupContainer.withdot:active -->

<div id="grandfather"> grandfather
<div id="father" class="brothers men"> father
Expand Down
8 changes: 8 additions & 0 deletions test/unit/selector_test.js
Expand Up @@ -397,6 +397,14 @@ new Test.Unit.Runner({

this.assertEqual(a, b);
},
testElementDownWithDotAndColon: function() {
var a = $('dupL4_dotcolon');
var b = $('dupContainer.withdot:active').down('#dupL4_dotcolon');
var c = $('dupContainer.withdot:active').select('#dupL4_dotcolon');

this.assertEqual(a, b);
this.assertEnumEqual([a], c);
},

testDescendantSelectorBuggy: function() {
var el = document.createElement('div');
Expand Down

0 comments on commit 059ce21

Please sign in to comment.