-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before this change, if you tried to search for "&" to match "Stuff & Nonsense", what we would do is html-escape _both_ things and compare the escaped strings. This works fine in the case where you just type "&". However, if you type "mp", that will match the html entity "&" in the middle of the html-escaped text we're comparing it to. Which is incorrect. Additionally, we highlight our "matched" result. When we do, we break up the entity so that the resulting HTML looks like: Stuff &a<em>mp</em>; Nonsense And you get to see what basically looks like garbage on the screen. ![screen garbage](https://camo.githubusercontent.com/b5e384f3f622f3560739c287c481e05a7b0668af/68747470733a2f2f646c2e64726f70626f7875736572636f6e74656e742e636f6d2f7370612f7470786279757478626b747069347a2f6c7566336c7835792e706e67) This commit fixes all of that by just comparing the actual text of things. We avoid the problem previous addressed in #2254 by escaping each piece of the to-be-highlighted option text before assembling it into HTML.
- Loading branch information
Arun Srinivasan
committed
Aug 22, 2017
1 parent
18a4c0b
commit 2c96f90
Showing
5 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
describe "Searching", -> | ||
it "should not match the actual text of HTML entities", -> | ||
tmpl = " | ||
<select data-placeholder='Choose an HTML Entity...'> | ||
<option value=''></option> | ||
<option value='This & That'>This & That</option> | ||
<option value='This < That'>This < That</option> | ||
</select> | ||
" | ||
|
||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
select.chosen({search_contains: true}) | ||
|
||
container = div.find(".chosen-container") | ||
container.trigger("mousedown") # open the drop | ||
|
||
# Both options should be active | ||
results = div.find(".active-result") | ||
expect(results.size()).toBe(2) | ||
|
||
# Search for the html entity by name | ||
search_field = div.find(".chosen-search input").first() | ||
search_field.val("mp") | ||
search_field.trigger("keyup") | ||
|
||
results = div.find(".active-result") | ||
expect(results.size()).toBe(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe "Searching", -> | ||
it "should not match the actual text of HTML entities", -> | ||
tmpl = " | ||
<select data-placeholder='Choose an HTML Entity...'> | ||
<option value=''></option> | ||
<option value='This & That'>This & That</option> | ||
<option value='This < That'>This < That</option> | ||
</select> | ||
" | ||
|
||
div = new Element('div') | ||
document.body.insert(div) | ||
div.update(tmpl) | ||
select = div.down('select') | ||
new Chosen(select, {search_contains: true}) | ||
|
||
container = div.down('.chosen-container') | ||
simulant.fire(container, 'mousedown') # open the drop | ||
|
||
# Both options should be active | ||
results = div.select('.active-result') | ||
expect(results.length).toBe(2) | ||
|
||
# Search for the html entity by name | ||
search_field = div.down(".chosen-search input") | ||
search_field.value = "mp" | ||
simulant.fire(search_field, 'keyup') | ||
|
||
results = div.select(".active-result") | ||
expect(results.length).toBe(0) |