Opened 12 years ago
Closed 12 years ago
#7236 closed bug (fixed)
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 [email protected] 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 (4)
comment:1 Changed 12 years ago by
Owner: | set to bradrees |
---|---|
Status: | new → pending |
comment:2 Changed 12 years ago by
Status: | pending → 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 12 years ago by
Component: | unfiled → selector |
---|---|
Keywords: | regression added |
Milestone: | 1.5 → 1.4.4 |
Priority: | undecided → high |
Status: | new → open |
comment:4 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
Fixed in this Sizzle commit: http://github.com/jeresig/sizzle/commit/bdd6ec790ce3884ed3583ebac9d490d98c0827d3
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.