Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retrieving children of <object> using contents() #4385

Merged
merged 1 commit into from May 6, 2019

Conversation

patocallaghan
Copy link
Contributor

@patocallaghan patocallaghan commented May 3, 2019

Fix for #4384

Summary

Since 0ba8e38, using contents() to get the children of an <object> is not working.

Taking this example HTML

<object type="application/x-shockwave-flash" width="200" height="300" id="penguin">
    <param name="movie" value="flash/penguin.swf">
    <param name="quality" value="high">
    <img src="images/penguin.jpg" width="200" height="300" alt="Penguin">
</object>

I'd expect the following to happen

jQuery(objectHtml).contents().length // => 3

But what actually happens is:

jQuery(objectHtml).contents().length // => 0

Changing the conditional to elem.contentDocument != null handles this case and the function returns the correct children.

Checklist

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Looks good to me.

@mgol
Copy link
Member

mgol commented May 4, 2019

Note to self: remember to cherry-pick this to 3.4-stable.

Copy link
Member

@timmywil timmywil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and has enough reviews.

@mgol mgol merged commit 4d865d9 into jquery:master May 6, 2019
@mgol
Copy link
Member

mgol commented May 6, 2019

I merged it and the newly added test fails in IE: http://swarm.jquery.org/result/3328701

mgol added a commit to mgol/jquery that referenced this pull request May 6, 2019
The original fix didn't account for the fact that in IE `<object>` elements
with no `data` attribute have an object `contentDocument`. The fix leverages
the fact that this special object has a null prototype.

Ref jquerygh-4384
Ref jquerygh-4385
@mgol
Copy link
Member

mgol commented May 6, 2019

PR with a fix for IE 11: #4390

mgol pushed a commit that referenced this pull request May 6, 2019
mgol added a commit to mgol/jquery that referenced this pull request May 6, 2019
The original fix didn't account for the fact that in IE `<object>` elements
with no `data` attribute have an object `contentDocument`. The fix leverages
the fact that this special object has a null prototype.

Ref jquerygh-4384
Ref jquerygh-4385
patocallaghan added a commit to intercom/jquery that referenced this pull request May 7, 2019
mgol added a commit that referenced this pull request May 8, 2019
The original fix didn't account for the fact that in IE `<object>` elements
with no `data` attribute have an object `contentDocument`. The fix leverages
the fact that this special object has a null prototype.

Closes gh-4390
Ref gh-4384
Ref gh-4385
mgol added a commit that referenced this pull request May 8, 2019
The original fix didn't account for the fact that in IE `<object>` elements
with no `data` attribute have an object `contentDocument`. The fix leverages
the fact that this special object has a null prototype.

(cherry-picked from ccbd6b9)

Closes gh-4390
Ref gh-4384
Ref gh-4385
@lock lock bot locked as resolved and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

None yet

4 participants