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

Regression: jQuery.text() returns "null" on HTMLDocument #5264

Closed
Krinkle opened this issue Jun 1, 2023 · 2 comments
Closed

Regression: jQuery.text() returns "null" on HTMLDocument #5264

Krinkle opened this issue Jun 1, 2023 · 2 comments
Milestone

Comments

@Krinkle
Copy link
Member

Krinkle commented Jun 1, 2023

When attempting to upgrade from jQuery 3.6.1 to 3.7.0 in MediaWiki, the Wikipedia ecosystem integration tests failed (https://gerrit.wikimedia.org/r/c/mediawiki/core/+/923762). Credit to @santhoshtr for finding the root cause and the minimum test case.

var doc = new DOMParser().parseFromString( '<span>text</span>', 'text/html' );
$(doc).text();
// Expected: "text"
// Actual: "null"

Link to test case

https://codepen.io/Krinkle/pen/eYPqYWm

     var doc = new DOMParser().parseFromString( '<span>text</span>', 'text/html' )
     document.write("Version: "+$jqv361.fn.jquery);
     document.write(". " + $jqv361(doc).text())
     document.write("<br>Version: "+$jqv370.fn.jquery);
     document.write(". " + $jqv370(doc).text())
Version: 3.6.4. text
Version: 3.7.0. null 

Other details

By placing a debugger statement in the test case and walking through, the difference is seen in the code.

In jQuery 3.6.x, we have Sizzle.getText with a combined conditional for several node types (1, 9, 11), where nodeType === 9 is for a Document object. The conditional block includes a fallback for textContent, because Document objects don't have a textContent property (only the inner <html> document element does).

Screenshot Screenshot

In jQuery 3.7.0, the equivalent jQuery.text function has the same conditional block but now unconditionally returns elem.textContent.

Screenshot
Krinkle added a commit to Krinkle/jquery that referenced this issue Jun 1, 2023
Krinkle added a commit to Krinkle/jquery that referenced this issue Jun 1, 2023
@mgol mgol added this to the 3.7.1 milestone Jun 1, 2023
@mgol
Copy link
Member

mgol commented Jun 1, 2023

Thanks for the detailed report! I'm not surprised one of the fallback removals in the end removed too much. 🙂

@parallels999
Copy link

hi @timmywil, please make 3.7.1 release 😥😥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants