Bug Tracker

Opened 11 years ago

Closed 11 years ago

#4325 closed bug (invalid)

[autocomplete] highlight function inserts "</strong>" for every character if variable term is empty string

Reported by: selfsimilar Owned by:
Priority: minor Milestone: 1.4
Component: plugin Version: 1.3.2
Keywords: [autocomplete] highlight Cc:
Blocked by: Blocking:


Using firebug, I'm able to determine that the regex used in $.Autocompleter.defaults highlight parameter function is faulty and doing a character by character replacement of itself prepended by <strong></strong> when var term is empty. For example we expect: <ul style="overflow: auto; max-height: 180px;"> <li class="ac_even ac_over"> <strong>FooBar</strong> </li> </ul>

But instead we get: <ul style="overflow: auto; max-height: 180px;"> <li class="ac_even ac_over"> <strong/> F <strong/> o <strong/> o <strong/> B <strong/> a <strong/> r <strong/> </li> </ul>

Suggested code edit starting at line 408:

highlight: function(value, term) {

if ("" != term) {

return value.replace(new RegExp("(?![&;]+;)(?!<[<>]*)(" + term.replace(/([\\$\(\)\[\]\{\}\*\.\+\?\|
])/gi, "
$1") + ")(?![
<>]*>)(?![&;]+;)", "gi"), "<strong>$1</strong>");

} else {

return value;


Change History (2)

comment:1 Changed 11 years ago by damian.biollo

A related fix may be to change the last "gi" parameter to "i" which will match only the first character.

I noticed that if your first character is repeated, then all instances get bolded, which is missleading since only the first character is matched (after you've typed only 1 char).

For example "Fluffy" would have 3 bold "f"'s after typing "f". After changing "gi" to "i", only the first F is bold. This is better since typing "fy" or "ffy" does *not* match Fluffy.

comment:2 Changed 11 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.