Skip to content

Commit 85fba3f

Browse files
josepsanzcampcaugnermgol
authored
Tooltip: Don't crash on empty content
Commit 1f2011e removed a `try-catch` around triggering the `remove` handlers in the `jQuery.cleanData` override. The `try-catch` was meant for old IE but it was also catching an error coming from the tooltip `remove` handler depending on being able to find a relevant tooltip. The `_find` method returns `null`, though, when the tooltip cotent is empty. Instead of restoring the `try-catch`, handle the `null` case in the `remove` handler. Fixes jquerygh-1990 Closes jquerygh-1994 Co-authored-by: Claas Augner <[email protected]> Co-authored-by: Michał Gołębiowski-Owczarek <[email protected]>
1 parent 1f0851b commit 85fba3f

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

tests/unit/tooltip/core.js

+70
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,74 @@ QUnit.test( "remove conflicting attributes from live region", function( assert )
254254
.tooltip( "open" );
255255
} );
256256

257+
// gh-1990
258+
QUnit.test( "don't crash on empty tooltip content", function( assert ) {
259+
var ready = assert.async();
260+
assert.expect( 1 );
261+
262+
var anchor = $( "#tooltipped1" ),
263+
input = anchor.next(),
264+
actions = [];
265+
266+
$( document ).tooltip( {
267+
show: false,
268+
hide: false,
269+
content: function() {
270+
var title = $( this ).attr( "title" );
271+
if ( title === "inputtitle" ) {
272+
return "";
273+
}
274+
return title;
275+
},
276+
open: function( event, ui ) {
277+
actions.push( "open:" + ui.tooltip.text() );
278+
},
279+
close: function( event, ui ) {
280+
actions.push( "close:" + ui.tooltip.text() );
281+
}
282+
} );
283+
284+
function step1() {
285+
anchor.simulate( "mouseover" );
286+
setTimeout( step2 );
287+
}
288+
289+
function step2() {
290+
anchor.simulate( "mouseout" );
291+
setTimeout( step3 );
292+
}
293+
294+
function step3() {
295+
input.simulate( "focus" );
296+
setTimeout( step4 );
297+
}
298+
299+
function step4() {
300+
input.simulate( "blur" );
301+
setTimeout( step5 );
302+
}
303+
304+
function step5() {
305+
anchor.simulate( "mouseover" );
306+
setTimeout( step6 );
307+
}
308+
309+
function step6() {
310+
anchor.simulate( "mouseout" );
311+
setTimeout( step7 );
312+
}
313+
314+
function step7() {
315+
assert.deepEqual( actions, [
316+
"open:anchortitle",
317+
"close:anchortitle",
318+
"open:anchortitle",
319+
"close:anchortitle"
320+
], "Tooltip opens and closes without crashing" );
321+
ready();
322+
}
323+
324+
step1();
325+
} );
326+
257327
} );

ui/widgets/tooltip.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ $.widget( "ui.tooltip", {
352352
// tooltips will handle this in destroy.
353353
if ( target[ 0 ] !== this.element[ 0 ] ) {
354354
events.remove = function() {
355-
this._removeTooltip( this._find( target ).tooltip );
355+
var targetElement = this._find( target );
356+
if ( targetElement ) {
357+
this._removeTooltip( targetElement.tooltip );
358+
}
356359
};
357360
}
358361

0 commit comments

Comments
 (0)