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

[Dropdown] Values are parsed incorrectly when they contain <, ≤, etc #1207

Closed
GammaGames opened this issue Dec 5, 2019 · 4 comments
Closed
Assignees
Labels
lang/javascript Anything involving JavaScript type/bug Any issue which is a bug or PR which fixes a bug
Milestone

Comments

@GammaGames
Copy link
Contributor

Bug Report

Steps to reproduce

  1. Create a dropdown
  2. Set its values to <, >, , and
  3. Get values and inspect the result

Expected result

Get the values for < and company

Actual result

Get &;amp;amp;amp;lt; and company. The number of &amp; might be related to number of selected values?

Testcase

https://jsfiddle.net/4cqtnf0d/

Screenshot (when possible)

image

Version

2.8.2

@GammaGames GammaGames added the state/awaiting-investigation Anything which needs more investigation label Dec 5, 2019
@y0hami y0hami added type/bug Any issue which is a bug or PR which fixes a bug lang/javascript Anything involving JavaScript and removed state/awaiting-investigation Anything which needs more investigation labels Dec 5, 2019
@y0hami y0hami added this to the 2.8.x milestone Dec 5, 2019
@GammaGames
Copy link
Contributor Author

GammaGames commented Dec 5, 2019

EDIT: Read next comment, this does work in some cases but there is another case I had not found until after I had written this one.

If anyone needs a workaround to fix this, I made a little function that will decode the values:

let decodeEntity = (text, iterations) => {
  iterations = iterations || 10;
  for(let i = 0; i < iterations; i++) {
    text = $("<div/>").html(text).text();
  }
  return text;
}

You pass it the text with HTML entities in it and the number of iterations. The second argument is the amount of times to decode the text, since the values are encoded every change it seems you have to do it the amount of changes the dropdown has had, since the old values will not be removed. The values array is still kinda buggy.

let decode_iterations = 0;
$('.ui.dropdown').dropdown({
  onChange: val => {
  	decode_iterations++;
  }
});
let values = $('.ui.dropdown').dropdown('get values').map(val => decodeEntity(val, decode_iterations));
console.log(values);

jsfiddle example

@GammaGames
Copy link
Contributor Author

GammaGames commented Dec 5, 2019

I think this is also messing with the changing logic, when a value is removed it can't find any match in the values for 1< so it doesn't remove the value in the array for 1&amp;amp;amp;amp;amp;amp;amp;amp;lt;. You can see that by unselecting elements in the dropdown in this fiddle.

image

This also highlights that the elements are further encoded, so I will modify the above decoding function to more accurately decode based on the number of changes, even if there is a larger problem relating to the values not being removed.

I would say that using $(".ui.dropdown a[data-value").toArray().map(el => $(el).data("value"); to get the values might be safer until this is fixed.

@lubber-de
Copy link
Member

Fixed by #1210 . See your adjusted jsfiddle here https://jsfiddle.net/kjqoa89e/

@lubber-de lubber-de added the state/has-pr An issue which has a related PR open label Dec 6, 2019
@lubber-de
Copy link
Member

@GammaGames I also fixed the remove label issue now
See your adjusted jsfiddle here https://jsfiddle.net/vckzmxaf/

@lubber-de lubber-de added tag/next-release/nightly Any issue which has a corresponding PR which has been merged and is available in the nightly build and removed state/has-pr An issue which has a related PR open labels Dec 22, 2019
@y0hami y0hami closed this as completed in fa50976 Dec 23, 2019
@y0hami y0hami removed the tag/next-release/nightly Any issue which has a corresponding PR which has been merged and is available in the nightly build label Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang/javascript Anything involving JavaScript type/bug Any issue which is a bug or PR which fixes a bug
Projects
None yet
Development

No branches or pull requests

3 participants