Bug Tracker

Modify

Ticket #7236 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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.

Change History

comment:1 Changed 3 years ago by addyosmani

  • Owner set to bradrees
  • Status changed from new to pending

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.

comment:2 Changed 3 years ago by bradrees

  • Status changed from pending to new

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.

comment:3 Changed 3 years ago by snover

  • Keywords regression added
  • Priority changed from undecided to high
  • Status changed from new to open
  • Component changed from unfiled to selector
  • Milestone changed from 1.5 to 1.4.4

comment:4 Changed 3 years ago by john

  • Status changed from open to closed
  • Resolution set to fixed

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.