Skip to main content

Bug Tracker

Side navigation

#7236 closed bug (fixed)

Opened October 18, 2010 11:26AM UTC

Closed October 22, 2010 04:43AM UTC

Sizzle.contains - compareDocumentPosition throws on older/lamer browsers

Reported by: bradrees Owned by: bradrees
Priority: high Milestone: 1.4.4
Component: selector Version: 1.4.3
Keywords: regression Cc:
Blocked by: Blocking:
Description

in version 1.4.3 there are two usages of compareDocumentPosition, the first on line 4400 is checked for support, however the second usage on line 4840 is not. On a browser that does not have this function it will throw when querying.

The function is 'Sizzle.contains', and when the browser does not have support for the function 'documentElement.contains' it drops to using 'compareDocumentPosition' without checking if that function exists. This was not a problem with 1.4.2.

I can repo this using the Samsung Internet@TV browser. I know it is a bit of an odd browser, but presumably a number of other older browsers will also exhibit this behaviour.

Attachments (0)
Change History (4)

Changed October 18, 2010 04:30PM UTC by addyosmani comment:1

owner: → bradrees
status: newpending

Can you please supply us with a test case that reproduces the bug mentioned?.

This bug may very well be flagged as invalid due to the low market share of the particular browser you're referring to, but it would assist us if you could check to see whether this issue is experienced in an old browser we do support such as IE6 for example.

Changed October 19, 2010 03:09PM UTC by bradrees comment:2

status: pendingnew

The old version was

var contains = document.compareDocumentPosition ? function (a, b)

{

return !!(a.compareDocumentPosition(b) & 16);

} : function (a, b)

{

return a !== b && (a.contains ? a.contains(b) : true);

};

while the new version is:

Sizzle.contains = document.documentElement.contains ? function(a, b){

return a !== b && (a.contains ? a.contains(b) : true);

} : function(a, b){

return !!(a.compareDocumentPosition(b) & 16);

};

As you can see there is a small logic flaw where in the original case the lack of support for both functions is handled, whereas in the second it is not.

My test case is when calling .has() on a jQuery object

$('#myElement').has('.myClass');

Example here: http://jsfiddle.net/AdV4C/2/

I haven't found any other browsers, but I would be concerned that the project would let this obvious new flaw through the net just because it does not exhibit itself in the mainstream browsers. I'm think there would be a number of embedded and mobile browsers that would not have support for these functions. Having said that I'll keep looking.

Changed October 19, 2010 07:35PM UTC by snover comment:3

component: unfiledselector
keywords: → regression
milestone: 1.51.4.4
priority: undecidedhigh
status: newopen

Changed October 22, 2010 04:43AM UTC by john comment:4

resolution: → fixed
status: openclosed