Skip to content

Commit d50e716

Browse files
Gabriel Schulhofarschmitz
Gabriel Schulhof
authored andcommitted
Widget: Avoid adding extra spaces to the result of this._classes(...)
Closes gh-1372
1 parent 46e1519 commit d50e716

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

tests/unit/widget/widget_core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,17 +608,20 @@ test( ".option() - deep option setter", function() {
608608
});
609609

610610
test( "_classes", function(){
611-
expect( 3 );
611+
expect( 4 );
612612
$.widget( "ui.testWidget", {
613613
options: {
614614
classes: {
615615
"test": "class1 class2",
616+
"testEmpty": "",
616617
"test2": "class3"
617618
}
618619
},
619620
_create: function() {
620621
equal( this._classes( "test" ), "test class1 class2" );
621622
equal( this._classes( "test2" ), "test2 class3" );
623+
equal( this._classes( "testEmpty" ), "testEmpty",
624+
"Computed value of empty-string-valued class key has no extra spaces" );
622625
equal( this._classes( "test test2" ), "test2 class3 test class1 class2" );
623626
}
624627
});

ui/widget.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ $.Widget.prototype = {
410410

411411
while ( i-- ) {
412412
out.push( parts[ i ] );
413-
out.push( classes[ parts[ i ] ] );
413+
414+
// Avoid extra spaces in the return value resulting from pushing an empty classes value
415+
if ( classes[ parts[ i ] ] ) {
416+
out.push( classes[ parts[ i ] ] );
417+
}
414418
}
415419

416420
return out.join( " " );

0 commit comments

Comments
 (0)