diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2022-11-14 18:36:53 +0100 |
---|---|---|
committer | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2022-11-14 23:17:23 +0100 |
commit | 3299236c898136dc1aa57dc5148811203e931895 (patch) | |
tree | 1a9b0c2629362272653a6c5d59f1cd8d5a27ace9 /src | |
parent | 0208224b5b76d54a39986f78aac97dbf1cccbe38 (diff) | |
download | jquery-3299236c898136dc1aa57dc5148811203e931895.tar.gz jquery-3299236c898136dc1aa57dc5148811203e931895.zip |
Selector:Manipulation: Fix DOM manip within template contents
The `<template/>` element `contents` property is a document fragment that may
have a `null` `documentElement`. In Safari 16 this happens in more cases due
to recent spec changes - in particular, even if that document fragment is
explicitly adopted into an outer document. We're testing both of those cases
now.
The crash used to happen in `jQuery.contains`. As it turns out, we don't need
to query the supposed container `documentElement` if it has the
`Node.DOCUMENT_NODE` (9) `nodeType`; we can call `.contains()` directly on
the `document`. That avoids the crash.
Fixes gh-5147
Closes gh-5158
Diffstat (limited to 'src')
-rw-r--r-- | src/selector/contains.js | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/selector/contains.js b/src/selector/contains.js index a62b97ab5..137b54388 100644 --- a/src/selector/contains.js +++ b/src/selector/contains.js @@ -2,15 +2,14 @@ import jQuery from "../core.js"; // Note: an element does not contain itself jQuery.contains = function( a, b ) { - var adown = a.nodeType === 9 ? a.documentElement : a, - bup = b && b.parentNode; + var bup = b && b.parentNode; return a === bup || !!( bup && bup.nodeType === 1 && ( // Support: IE 9 - 11+ // IE doesn't have `contains` on SVG. - adown.contains ? - adown.contains( bup ) : + a.contains ? + a.contains( bup ) : a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 ) ); }; |