Skip to content
/ jquery Public
forked from jquery/jquery

Commit

Permalink
Core: Fix regression in jQuery.text() on HTMLDocument objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jun 1, 2023
1 parent 992a665 commit 57065e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ jQuery.extend( {
// Do not traverse comment nodes
ret += jQuery.text( node );
}
} else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
} else if ( nodeType === 1 || nodeType === 11 ) {
return elem.textContent;
} if ( nodeType === 9 ) {
return elem.documentElement.textContent;
} else if ( nodeType === 3 || nodeType === 4 ) {
return elem.nodeValue;
}
Expand Down
7 changes: 5 additions & 2 deletions test/unit/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function manipulationFunctionReturningObj( value ) {

QUnit.test( "text()", function( assert ) {

assert.expect( 5 );
assert.expect( 6 );

var expected, frag, $newLineTest;
var expected, frag, $newLineTest, doc;

expected = "This link has class=\"blog\": Simon Willison's Weblog";
assert.equal( jQuery( "#sap" ).text(), expected, "Check for merged text of more then one element." );
Expand All @@ -52,6 +52,9 @@ QUnit.test( "text()", function( assert ) {
assert.equal( $newLineTest.text(), "test\ntesty", "text() does not remove new lines (trac-11153)" );

$newLineTest.remove();

doc = new DOMParser().parseFromString( "<span>example</span>", "text/html" );
assert.equal( jQuery( doc ).text(), "example", "text() on HTMLDocument (gh-5264)" );
} );

QUnit.test( "text(undefined)", function( assert ) {
Expand Down

0 comments on commit 57065e2

Please sign in to comment.