Skip to content

Commit adcf9b6

Browse files
committed
Labels: Handle empty sets
Fixes #15184
1 parent 0d25a36 commit adcf9b6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

tests/unit/core/core.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ QUnit.test( "uniqueId / removeUniqueId", function( assert ) {
142142
} );
143143

144144
QUnit.test( "Labels", function( assert ) {
145-
assert.expect( 2 );
145+
assert.expect( 3 );
146146

147147
var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ];
148148
var dom = $( "#labels-fragment" );
@@ -165,6 +165,8 @@ QUnit.test( "Labels", function( assert ) {
165165
// Detach the dom to test on a fragment
166166
dom.detach();
167167
testLabels( "document fragments" );
168+
169+
assert.equal( $().labels().length, 0, "No element" );
168170
} );
169171

170172
( function() {

ui/labels.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
return $.fn.labels = function() {
2828
var ancestor, selector, id, labels, ancestors;
2929

30+
if ( !this.length ) {
31+
return this.pushStack( [] );
32+
}
33+
3034
// Check control.labels first
3135
if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
3236
return this.pushStack( this[ 0 ].labels );

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy