Fix quote and ampersand HTML escape in dropdown#3205
Fix quote and ampersand HTML escape in dropdown#3205lubber-de merged 13 commits intofomantic:developfrom
Conversation
|
For unknown reasons to me, multiple values are escaped by default by I tested both (t/f) |
There was a problem hiding this comment.
I took the time and went through (possibly) all related old issues and PRs the past years.
Most of them work fine with this PR. 👍
However, i found 3 of them which are now broken when this PR (de27144) is applied:
1. Original Issue: #1373, Original PR: #1770
FUI 2.9.4
https://jsfiddle.net/lubber/23htdnw0/1/
--> works
Your PR applied
https://jsfiddle.net/lubber/gmh5reoy/5/
--> fails (even though preserveHTML is true, the labels are encoded)
--> fails (when preserveHTML is false, ampersand is double encoded)
2. Original Issue: #2782, Original PR: #2790
Mentioned example c)
FUI 2.9.4
https://jsfiddle.net/lubber/q8hL21yg/1/
--> works
Your PR applied
https://jsfiddle.net/lubber/zap03L4k/5/
--> fails (Ampersand always encoded even when preserveHTML is true.
--> fails (When preserveHTML is false, the ampersand is double encoded)
3. Original Issue: #2817, Original PR: #2705
FUI 2.9.4
https://jsfiddle.net/lubber/97druzp4/1/
--> works
Your PR applied
https://jsfiddle.net/lubber/rhs4aq7u/3/
--> fails (always encoded)
|
Thank you for the extensive review. I extracted changes I consider safe into #3212 to minimize the LoC changed of this PR to discuss it later. |
extracted from #3205 We use here a trick that HTML attributes can be escaped the same way as HTML values - jsfiddle.net/45q9zL7j, thus HTML attributes does not need a separate escape function. Under normal usage this PR should imply no function change.
extracted from #3205 The new code is simpler, faster and easy to fix ampersand escape later. No functional change.
85ee58e to
cc0663a
Compare
"module.get.values()" escape the values when multiple
Good catch, fixed. |
|
Two things left for me atm: 1stThe fix from fddfe7a should also be applied to Fomantic-UI/src/definitions/modules/dropdown.js Line 2790 in fddfe7a so it also becomes html = settings.templates.addition(module.add.variables(message.addResult, settings.templates.escape(value, settings)));2ndAs i explained the meaning of preserveHTML in #3205 (comment) should be vice versa. It should be either module.add.userSuggestion(!settings.preserveHTML
? module.escape.htmlEntities(query)
: query);or module.add.userSuggestion(settings.preserveHTML
? query
: module.escape.htmlEntities(query));But the related change was implemented in #3224, so it might be adjusted there, if you want the other PR to be merged first |
Fixed by me, my mistake. I now checked all
You are worried about a995f2f. No, it makes sense - with |
Sure thing 👍🏼 That's why it was basically always encoded before just in case.
Alright. I debugged it down now more deeply and i can confirm, after your latest fixes, that the usersuggestion is now safely encoded when finally being added to the DOM 🥳 Just to clarify/summarize (for myself, if i ever need to rethink/reconfirm this in some later situation/refactoring)
Those 2 situations, in addition to the found XSS use case yesterday, made me not believing the code was correct... until today 😉
@mvorisek Thanks for being patient with me (again) and explaining all my confusionI will now look into the other modules usages for the escape method which were also adjusted in this PR to finally merge your both PRs |
for all modules except dropdown
extracted from #3205 And fix many double encoding issues. All escape functions must be lossless and must return the same value when called again on a reverse function. When using preserveHTML=false and the text is read from innerHTML input (<option>xxx</option>), & must be encoded in HTML code as &amp; to be preserved 1:1, This is due & -> & browser HTML normalization. Explained in [1], [2], [3]. [1] original issue: #2782 [2] browser behaviour: jsfiddle.net/wdyjfvz0 [3] how to encode innerHTML for <option> tag: 3v4l.org/E2BQY
lubber-de
left a comment
There was a problem hiding this comment.
LGTM, Thanks for your patience :)




merge after #3224
fix #3199