Bug Tracker

Opened 12 years ago

Closed 10 years ago

Last modified 8 years ago

#2844 closed bug (invalid)

Autocomplete plugin uses innerHTML and causes troubles on XHTML pages

Reported by: Messere Owned by: joern
Priority: major Milestone:
Component: plugin Version:
Keywords: autocomplete xhtml innerHTML createTextNode Cc:
Blocked by: Blocking:

Description

In dataToDom and findValueCallback methods innerHTML properity is used to fill list elements with results. While this is tolerable for HTML4 formatted pages it breaks plugin in XHTML environment.

Consider server side script returning results that contain ampersand ("A&M" for example). If you return it without modification it'll create the following invalid DOM:

<ul>
<li>A&M</li>
</ul>

(that happens because innerHTML does not properly escape passed value and does not convert & to entity &amp;).

If you return "A&amp;M" from server side script it'll create valid DOM, but will put invalid value in select element ("A&amp;M" instead of "A&M"), so this is not a good solution.

The right thing to do to use document.createTextNode() method instead of innerHTML:

var li = document.createElement("li");
var tn = document.createTextNode(row[0]);
li.appendChild(tn);

Change History (2)

comment:1 Changed 12 years ago by flesler

Owner: set to joern

comment:2 Changed 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

This is not a jQuery core bug. Please report plugin bugs to the plugin's author, or ask on the jQuery forums. jQuery UI bugs should be reported on the UI bug tracker, http://dev.jqueryui.com .

Note: See TracTickets for help on using tickets.