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

Getting children of <object> tag with contents() not working correctly #4384

Closed
patocallaghan opened this issue May 3, 2019 · 2 comments · Fixed by GulajavaMinistudio/jquery#90

Comments

@patocallaghan
Copy link
Contributor

@patocallaghan patocallaghan commented May 3, 2019

Description

Version: jQuery 3.4.1

Since 0ba8e38 it appears that using contents() to get the children of an <object> is not working as expected.

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

This happens because on this line

jquery/src/traversing.js

Lines 148 to 149 in 110802c

if ( typeof elem.contentDocument !== "undefined" ) {
return elem.contentDocument;
it only checks if elem.contentDocument is not undefined. But in this scenario elem.contentDocument is null so the conditional is truthy and enters the if block and returns null for the contents.

If we change the conditional to be elem.contentDocument != null it works correctly.

Link to test case

https://codepen.io/patocallaghan/pen/bybaWv?editors=0011

I have a PR to fix it but I wanted to open an issue first.

@mgol
Copy link
Member

@mgol mgol commented May 4, 2019

Thanks for the report! This is a regression from jQuery 3.3.1 so I added the 3.4.2 milestone.

@mgol
Copy link
Member

@mgol mgol commented May 4, 2019

PR: #4385

@mgol mgol closed this as completed in 4d865d9 May 6, 2019
mgol added a commit to mgol/jquery that referenced this issue 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 pushed a commit that referenced this issue May 6, 2019
mgol added a commit to mgol/jquery that referenced this issue 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 issue May 7, 2019
mgol added a commit that referenced this issue 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 issue 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 a pull request may close this issue.

2 participants