Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#5275 closed bug (fixed)

suggestions are not html-encoded

Reported by: wouter Owned by:
Priority: minor Milestone: 1.8.3
Component: ui.autocomplete Version: 1.8rc3
Keywords: Cc:
Blocked by: Blocking:


If a suggestion in the auto-complete list contains characters such as < or &, these are not html-encoded, possibly messing up the html.

(When the suggestion is clicked the value that appears in the textbox is html-encoded.)

This is the solution I used:

	_renderItem: function( ul, item) {
		var a = $("<a></a>").text(item.label);
		return $( "<li></li>" )
			.data( "item.autocomplete", item )
			.append( a )
			.appendTo( ul );

Change History (7)

comment:1 Changed 13 years ago by Scott González

Resolution: invalid
Status: newclosed

This is intended, to allow flexibility in the displays. If you want to prevent using HTML and only allow text, you can change the behavior. If you need help, please ask on the forum.

comment:2 Changed 13 years ago by chungwu

Resolution: invalid
Status: closedreopened

Using an HTML as a label is not a good way to customize display, as that HTML string is also the string that the widget will be regexp-filtering on (which is most likely not what the user wanted to do).

It would be nice to have _renderItem, by default, assume item.label is plaintext and Do The Safe Thing. More sophisticated users can override this behavior if they want to use fancy html (as the custom renderer demo does here:

comment:3 Changed 13 years ago by erikrose

Also, the HTML string is, by default, what will appear in the text field once chosen. I add my vote for HTML escaping by default.

comment:4 Changed 13 years ago by erikrose

Er, never mind; you already said that. *needs breakfast*

comment:5 Changed 13 years ago by Scott González

Milestone: TBD1.9
Resolution: fixed
Status: reopenedclosed

Defaulting to plaintext and defining your own render method for HTML and other complex displays makes sense. Fixed in 1f2cfb9.

comment:6 Changed 13 years ago by Scott González


comment:7 Changed 13 years ago by Scott González

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.

Changeset: 1f2cfb942f8ac5549b1fe3172501e3486415530e

Note: See TracTickets for help on using tickets.