Skip to content
New issue

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

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

Already on GitHub? # to your account

[Dropdown] Remote content should handle quotes in item value properly #4592

Open
hejmsdz opened this issue Sep 26, 2016 · 7 comments
Open

[Dropdown] Remote content should handle quotes in item value properly #4592

hejmsdz opened this issue Sep 26, 2016 · 7 comments
Milestone

Comments

@hejmsdz
Copy link

hejmsdz commented Sep 26, 2016

When a JSON response for a remote dropdown contains quotes inside a string, it's misinterpreted as the end of an attribute. See http://jsfiddle.net/1xLsau44/10/ and try inspecting $(".menu").

@awgv awgv added this to the Needs Milestone milestone Mar 11, 2017
@thekid
Copy link

thekid commented Sep 3, 2017

The above jsfiddle does not work anymore, but I've experienced the same problem.

JSON

This is what the server returns:

[{"label":"He said: \"" is a quote\"","value":"hello-html","created":"2017-09-03"}]

Wiring

This is the onResponse() handler I use to transform the results:

$('.ui.dropdown').dropdown({
  apiSettings: {
    url: '/topics/complete?term={query}',
    onResponse: function(results) {
      var response = { success : true, results : []};
      $.each(results, function(index, item) {
        var topic = escapeHTML(item.label);
        response.results.push({
          name  : null === item.created ? '+ ' + topic : topic,
          value : topic,
          text  : escapeHTML(topic)   // Yes, it needs to be escaped twice!
        });
      });
      return response;
    }
  }
});

escapeHTML() takes care of replacing <>"& with their respective entities

Observations

  • First of all, needing to escape HTML in the results is weird; I assume this is so HTML fragments can be inserted; same goes for .search(), so it seems intentional.
  • Having to escape twice for the text key feels like a bug (try with HTML fragments such as <script>alert(1)</script> to see the effect if omitted!)
  • I found Values with double quotes raises error UI-Dropdown#8 which is closed and seems to have addressed a similar issue by replacing " with &quot;. This turns He said: "&quot; is a quote" into He said: &quot;&quot; is a quote&quot;, which is definitely a bug - the value is no longer the same

Fix

I've put together a fix at https://gist.github.com/thekid/39580dba8dba5b227d5ab57f4ca5ac5e. The diff is against semantic.js from the dist folder, the real fix will probably need to be made over at https://github.com/Semantic-Org/UI-Dropdown

@stale
Copy link

stale bot commented Jun 5, 2018

There has been no activity in this thread for 90 days. While we care about every issue and we’d love to see this fixed, the core team’s time is limited so we have to focus our attention on the issues that are most pressing. Therefore, we will likely not be able to get to this one.

However, PRs for this issue will of course be accepted and welcome!

If there is no more activity in the next 90 days, this issue will be closed automatically for housekeeping. To prevent this, simply leave a reply here. Thanks!

@stale stale bot added the stale label Jun 5, 2018
@thekid
Copy link

thekid commented Jun 5, 2018

This is a confirmed bug, how can I aid in fixing it? Can you give me some directions?

@stale stale bot removed the stale label Jun 5, 2018
@jbwl
Copy link

jbwl commented Aug 3, 2018

This is pretty crucial for select tags containing arbitrary data for option values - I'd like this fixed please.

@y0hami y0hami modified the milestones: Needs Milestone, 2.3.x Aug 3, 2018
@jbwl
Copy link

jbwl commented Sep 26, 2018

As this wasn't addressed in 2.4., I'd like to find a solution here, even if it's a workaround or hack.

@jbwl
Copy link

jbwl commented Oct 19, 2018

Another release (2.4.1) and it seems this bug hasn't been addressed, at least according to the changelog. Please let us know how we can assist you.

@lubber-de

This comment was marked as spam.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

6 participants