Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
18e7a53d
Commit
18e7a53d
authored
Oct 26, 2012
by
Oleg
Committed by
Rick Waldron
Oct 26, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Elements created from html strings have a parentnode. Fixes #12392
parent
4f0e1e7c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
14 deletions
+48
-14
manipulation.js
src/manipulation.js
+26
-9
manipulation.js
test/unit/manipulation.js
+22
-5
No files found.
src/manipulation.js
View file @
18e7a53d
function
createSafeFragment
(
document
)
{
function
createSafeFragment
(
document
)
{
var
list
=
nodeNames
.
split
(
"|"
),
var
list
=
nodeNames
.
split
(
"|"
),
safeFrag
=
document
.
createDocumentFragment
();
safeFrag
=
document
.
createDocumentFragment
();
if
(
safeFrag
.
createElement
)
{
if
(
safeFrag
.
createElement
)
{
while
(
list
.
length
)
{
while
(
list
.
length
)
{
...
@@ -49,9 +49,9 @@ wrapMap.th = wrapMap.td;
...
@@ -49,9 +49,9 @@ wrapMap.th = wrapMap.td;
// IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags,
// IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags,
// unless wrapped in a div with non-breaking characters in front of it.
// unless wrapped in a div with non-breaking characters in front of it.
if
(
!
jQuery
.
support
.
htmlSerialize
)
{
if
(
!
jQuery
.
support
.
htmlSerialize
)
{
wrapMap
.
_default
=
[
1
,
"X<div>"
,
"
</div>
"
];
wrapMap
.
_default
=
[
1
,
"X<div>"
,
""
];
// Fixes #11280
// Fixes #11280
wrapMap
.
param
=
[
1
,
"X<object>"
,
"
</object>
"
];
wrapMap
.
param
=
[
1
,
"X<object>"
,
""
];
// Fixes #11280. HTMLParam name attribute added to avoid IE6-8 parsing issue.
// Fixes #11280. HTMLParam name attribute added to avoid IE6-8 parsing issue.
addMandatoryAttributes
=
function
(
elem
)
{
addMandatoryAttributes
=
function
(
elem
)
{
// If it's a param
// If it's a param
...
@@ -650,7 +650,7 @@ jQuery.extend({
...
@@ -650,7 +650,7 @@ jQuery.extend({
},
},
clean
:
function
(
elems
,
context
,
fragment
,
scripts
)
{
clean
:
function
(
elems
,
context
,
fragment
,
scripts
)
{
var
i
,
j
,
elem
,
tag
,
wrap
,
depth
,
div
,
hasBody
,
tbody
,
handleScript
,
jsTags
,
var
i
,
j
,
elem
,
tag
,
wrap
,
depth
,
parent
,
div
,
hasBody
,
tbody
,
handleScript
,
jsTags
,
safe
=
context
===
document
&&
safeFragment
,
safe
=
context
===
document
&&
safeFragment
,
ret
=
[];
ret
=
[];
...
@@ -676,8 +676,7 @@ jQuery.extend({
...
@@ -676,8 +676,7 @@ jQuery.extend({
}
else
{
}
else
{
// Ensure a safe container in which to render the html
// Ensure a safe container in which to render the html
safe
=
safe
||
createSafeFragment
(
context
);
safe
=
safe
||
createSafeFragment
(
context
);
div
=
context
.
createElement
(
"div"
);
div
=
div
||
safe
.
appendChild
(
context
.
createElement
(
"div"
)
);
safe
.
appendChild
(
div
);
// Fix "XHTML"-style tags in all browsers
// Fix "XHTML"-style tags in all browsers
elem
=
elem
.
replace
(
rxhtmlTag
,
"<$1></$2>"
);
elem
=
elem
.
replace
(
rxhtmlTag
,
"<$1></$2>"
);
...
@@ -719,9 +718,10 @@ jQuery.extend({
...
@@ -719,9 +718,10 @@ jQuery.extend({
}
}
elem
=
div
.
childNodes
;
elem
=
div
.
childNodes
;
parent
=
div
;
//
Take out of fragment container (we need a fresh div each time)
//
Remember the top-level container for proper cleanup
div
.
parentNode
.
removeChild
(
div
)
;
div
=
safe
.
lastChild
;
}
}
}
}
...
@@ -729,14 +729,31 @@ jQuery.extend({
...
@@ -729,14 +729,31 @@ jQuery.extend({
ret
.
push
(
elem
);
ret
.
push
(
elem
);
}
else
{
}
else
{
jQuery
.
merge
(
ret
,
elem
);
jQuery
.
merge
(
ret
,
elem
);
// Fix #12392
if
(
parent
)
{
// for WebKit and IE > 9
parent
.
textContent
=
""
;
// for oldIE
while
(
parent
.
firstChild
)
{
parent
.
removeChild
(
parent
.
firstChild
);
}
parent
=
null
;
}
}
}
}
}
// Fix #11356: Clear elements from safeFragment
// Fix #11356: Clear elements from safeFragment
if
(
div
)
{
if
(
div
)
{
elem
=
div
=
safe
=
null
;
safe
.
removeChild
(
div
)
;
}
}
elem
=
div
=
safe
=
null
;
// Reset defaultChecked for any radios and checkboxes
// Reset defaultChecked for any radios and checkboxes
// about to be appended to the DOM in IE 6/7 (#8060)
// about to be appended to the DOM in IE 6/7 (#8060)
if
(
!
jQuery
.
support
.
appendChecked
)
{
if
(
!
jQuery
.
support
.
appendChecked
)
{
...
...
test/unit/manipulation.js
View file @
18e7a53d
...
@@ -473,11 +473,11 @@ test("append(param) to object, see #11280", function() {
...
@@ -473,11 +473,11 @@ test("append(param) to object, see #11280", function() {
expect
(
11
);
expect
(
11
);
var
objectElement
=
document
.
createElement
(
"object"
),
var
objectElement
=
document
.
createElement
(
"object"
),
$objectElement
=
jQuery
(
objectElement
),
$objectElement
=
jQuery
(
objectElement
),
paramElement
=
jQuery
(
"<param type='wmode' value='transparent'/>"
),
paramElement
=
jQuery
(
"<param type='wmode' value='transparent'/>"
),
paramElement2
=
jQuery
(
"<param name='' type='wmode2' value='transparent2' />"
),
paramElement2
=
jQuery
(
"<param name='' type='wmode2' value='transparent2' />"
),
paramElement3
=
jQuery
(
"<param type='wmode' name='foo' >"
),
paramElement3
=
jQuery
(
"<param type='wmode' name='foo' >"
),
newObject
=
jQuery
(
"<object><param type='foo' ><param name='' value='foo2'/><param type='baz' name='bar'></object>"
);
newObject
=
jQuery
(
"<object><param type='foo' ><param name='' value='foo2'/><param type='baz' name='bar'></object>"
);
equal
(
objectElement
.
childNodes
.
length
,
0
,
"object did not have childNodes previously"
);
equal
(
objectElement
.
childNodes
.
length
,
0
,
"object did not have childNodes previously"
);
...
@@ -613,6 +613,23 @@ test("append HTML5 sectioning elements (Bug #6485)", function () {
...
@@ -613,6 +613,23 @@ test("append HTML5 sectioning elements (Bug #6485)", function () {
equal
(
aside
.
length
,
1
,
"HTML5 elements do not collapse their children"
);
equal
(
aside
.
length
,
1
,
"HTML5 elements do not collapse their children"
);
});
});
test
(
"jQuery.clean, #12392"
,
function
()
{
expect
(
6
);
var
elems
=
jQuery
.
clean
([
"<div>test div</div>"
,
"<p>test p</p>"
]);
ok
(
elems
[
0
].
parentNode
==
null
||
elems
[
0
].
parentNode
.
nodeType
===
11
,
"parentNode should be documentFragment or null"
);
ok
(
elems
[
1
].
parentNode
==
null
||
elems
[
1
].
parentNode
.
nodeType
===
11
,
"parentNode should be documentFragment or null"
);
equal
(
elems
[
0
].
innerHTML
,
"test div"
,
"Content should be preserved"
);
equal
(
elems
[
1
].
innerHTML
,
"test p"
,
"Content should be preserved"
);
equal
(
jQuery
.
clean
([
"<span><span>"
]).
length
,
1
,
"Incorrect html-strings should not break anything"
);
elems
=
jQuery
.
clean
([
"<td><td>"
]);
ok
(
elems
[
1
].
parentNode
==
null
||
elems
[
1
].
parentNode
.
nodeType
===
11
,
"parentNode should be documentFragment or null"
);
});
if
(
jQuery
.
css
)
{
if
(
jQuery
.
css
)
{
test
(
"HTML5 Elements inherit styles from style rules (Bug #10501)"
,
function
()
{
test
(
"HTML5 Elements inherit styles from style rules (Bug #10501)"
,
function
()
{
expect
(
1
);
expect
(
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment