Skip to content

Commit 1f2cfb9

Browse files
committed
Autocomplete: Render items as text, not HTML. Fixes #5275 - suggestions are not html-encoded.
As noted in the ticket, it's probably better to default to unstyled items to prevent problems. Users can still implement their own rendering method as shown in the custom data and display demo.
1 parent 7deb873 commit 1f2cfb9

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

demos/autocomplete/combobox.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
minLength: 0
5555
})
5656
.addClass("ui-widget ui-widget-content ui-corner-left");
57+
input.data("autocomplete")._renderItem = function( ul, item) {
58+
return $( "<li></li>" )
59+
.data( "item.autocomplete", item )
60+
.append( "<a>" + item.label + "</a>" )
61+
.appendTo( ul );
62+
};
5763
$("<button>&nbsp;</button>")
5864
.attr("tabIndex", -1)
5965
.attr("title", "Show All Items")

demos/autocomplete/search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
$q = strtolower($_GET["term"]);
44
if (!$q) return;
55
$items = array(
6-
"Great <em>Bittern</em>"=>"Botaurus stellaris",
7-
"Little <em>Grebe</em>"=>"Tachybaptus ruficollis",
6+
"Great Bittern"=>"Botaurus stellaris",
7+
"Little Grebe"=>"Tachybaptus ruficollis",
88
"Black-necked Grebe"=>"Podiceps nigricollis",
99
"Little Bittern"=>"Ixobrychus minutus",
1010
"Black-crowned Night Heron"=>"Nycticorax nycticorax",

ui/jquery.ui.autocomplete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ $.widget( "ui.autocomplete", {
304304
_renderItem: function( ul, item) {
305305
return $( "<li></li>" )
306306
.data( "item.autocomplete", item )
307-
.append( "<a>" + item.label + "</a>" )
307+
.append( $( "<a></a>" ).text( item.label ) )
308308
.appendTo( ul );
309309
},
310310

0 commit comments

Comments
 (0)