Bug Tracker

Modify

Ticket #4325 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

[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:
Blocking: Blocked by:

Description

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

comment:1 Changed 4 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 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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 .

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.