Skip to content

Commit

Permalink
Fix mootools#31 - ~ div would throw when QSA was used
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian committed Mar 9, 2011
1 parent a2796ca commit 394c5ff
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion SlickSpec/Configuration.js
Expand Up @@ -21,7 +21,7 @@ Configuration.sets = {
'specs': {
path: 'specs/',
files: [
'unit', 'syntax', 'api', 'engine_bugs', 'html', 'html5',
'unit', 'syntax', 'api', 'engine_bugs', 'html', 'html5',
'select_nth-child', 'select_exhaustive', 'mock_template',
'isxml', 'xml',
'match', 'parser',
Expand Down
4 changes: 4 additions & 0 deletions SlickSpec/mocks/query_test-slick.html
Expand Up @@ -12,5 +12,9 @@
<div id="divtabindex0" tabindex="0">some</div>
<div id="divtabindex1" tabindex="1">some</div>
<div id="divtabindexnull">some</div>

<div id="one"><i>text</i></div>
<div id="two"></div>

</body>
</html>
4 changes: 2 additions & 2 deletions SlickSpec/setup.js
Expand Up @@ -19,7 +19,7 @@ global.onload = function(){
if (!Browser.ie || Browser.version > 8){
Mock.CreateTemplate('Generic XHTML', '../mocks/template.xhtml');
Mock.CreateTemplate('Generic XML', '../mocks/template.xml');
Mock.CreateTemplate('SVG', '../mocks/mootools_logo.svg');
Mock.CreateTemplate('SVG', '../mocks/MooTools_Logo.svg');
}

if (Browser.ie){
Expand All @@ -39,7 +39,7 @@ global.onload = function(){


new Mock.Request('XML responseXML', '../mocks/xml.xml');
new Mock.Request('SVG responseXML', '../mocks/mootools_logo.svg');
new Mock.Request('SVG responseXML', '../mocks/MooTools_Logo.svg');

// Setup

Expand Down
12 changes: 11 additions & 1 deletion SlickSpec/specs/html.js
Expand Up @@ -32,6 +32,16 @@ describe('Slick', function(){
itShouldFind(2, 'body [tabindex="1"]');
itShouldFind(4, 'body [tabindex]');

it('should find `~`', function(){
expect(context.SELECT1(context.document.getElementById('one'), '~')).not.toBeNull();
});
it('should find `~div`', function(){
expect(context.SELECT1(context.document.getElementById('one'), '~div')).not.toBeNull();
});
it('should find `> i`', function(){
expect(context.SELECT1(context.document.getElementById('one'), '> i')).not.toBeNull();
});

});

};
};
9 changes: 9 additions & 0 deletions Source/Slick.Finder.js
Expand Up @@ -63,6 +63,7 @@ local.setDocument = function(document){
= features.brokenMixedCaseQSA
= features.brokenGEBCN
= features.brokenCheckedQSA
= features.brokenGeneralSiblingCombinator
= features.brokenEmptyAttributeQSA
= features.isHTMLDocument
= features.nativeMatchesSelector
Expand Down Expand Up @@ -146,6 +147,13 @@ local.setDocument = function(document){
features.brokenCheckedQSA = (testNode.querySelectorAll(':checked').length == 0);
} catch(e){};

try {
testNode.innerHTML = '<div id="foo"></div><div></div>';
features.brokenGeneralSiblingCombinator = !(testNode.getElementById('foo').querySelector('~ div'));

This comment has been minimized.

Copy link
@seanmonstar

seanmonstar Mar 9, 2011

change this to '#foo ~ div' i'd say

This comment has been minimized.

Copy link
@subtleGradient

subtleGradient Mar 9, 2011

I say add both

This comment has been minimized.

Copy link
@seanmonstar

seanmonstar Mar 9, 2011

well '~ div' is illegal, so it will always fail. checing '#foo ~ div' will only fail if qSA is bugged.

http://jsfiddle.net/GyceA/12/

} catch(e){
features.brokenGeneralSiblingCombinator = true;
}

// IE returns incorrect results for attr[*^$]="" selectors on querySelectorAll
try {
testNode.innerHTML = '<a class=""></a>';
Expand Down Expand Up @@ -331,6 +339,7 @@ local.search = function(context, expression, append, first){

if (!this.isHTMLDocument || this.brokenMixedCaseQSA || qsaFailExpCache[expression] ||
(this.brokenCheckedQSA && expression.indexOf(':checked') > -1) ||
(this.brokenGeneralSiblingCombinator) ||
(this.brokenEmptyAttributeQSA && reEmptyAttribute.test(expression)) || Slick.disableQSA) break querySelector;

var _expression = expression;
Expand Down

1 comment on commit 394c5ff

@subtleGradient
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Please sign in to comment.