Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape optgroup label when appending to HTML. #2881

Merged
merged 1 commit into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class AbstractChosen

group_el = document.createElement("li")
group_el.className = classes.join(" ")
group_el.innerHTML = group.highlighted_html or group.label
group_el.innerHTML = group.highlighted_html or this.escape_html(group.label)
group_el.title = group.title if group.title

this.outerHTML(group_el)
Expand Down
17 changes: 16 additions & 1 deletion spec/jquery/searching.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,22 @@ describe "Searching", ->
expect(div.find(".active-result").length).toBe(1)
expect(div.find(".active-result").first().html()).toBe("<em>A</em> &amp; B")

it "renders optgroups correctly when they contain characters that require HTML encoding", ->
it "renders optgroups correctly when they contain html encoded tags", ->
div = $("<div>").html("""
<select>
<optgroup label="A &lt;b&gt;hi&lt;/b&gt; B">
<option value="Item">Item</option>
</optgroup>
</select>
""")

div.find("select").chosen()
div.find(".chosen-container").trigger("mousedown") # open the drop

expect(div.find(".group-result").length).toBe(1)
expect(div.find(".group-result").first().html()).toBe("A &lt;b&gt;hi&lt;/b&gt; B")

it "renders optgroups correctly when they contain characters that require HTML encoding when searching", ->
div = $("<div>").html("""
<select>
<optgroup label="A &amp; B">
Expand Down
16 changes: 16 additions & 0 deletions spec/proto/searching.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ describe "Searching", ->
expect(div.down(".active-result").innerHTML).toBe("<em>A</em> &amp; B")

it "renders optgroups correctly when they contain characters that require HTML encoding", ->
div = new Element("div")
div.update("""
<select>
<optgroup label="A &lt;b&gt;hi&lt;/b&gt; B">
<option value="Item">Item</option>
</optgroup>
</select>
""")

new Chosen(div.down("select"))
simulant.fire(div.down(".chosen-container"), "mousedown") # open the drop

expect(div.select(".group-result").length).toBe(1)
expect(div.down(".group-result").innerHTML).toBe("A &lt;b&gt;hi&lt;/b&gt; B")

it "renders optgroups correctly when they contain characters that require HTML encoding when searching", ->
div = new Element("div")
div.update("""
<select>
Expand Down