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

html entities problem #385

Closed
yehudah opened this issue Jul 16, 2015 · 2 comments
Closed

html entities problem #385

yehudah opened this issue Jul 16, 2015 · 2 comments

Comments

@yehudah
Copy link

yehudah commented Jul 16, 2015

Hello,

When my suggestions have double quotes the script convert the visual char to the releavent html entities.

I searched and didn't found someone complain on the same issue and that very odd.

I'm using jquery 1.11.3 and the latest plugin release.
the website is in hebrew.

Thanks.

@tkirda
Copy link
Member

tkirda commented Jul 16, 2015

Some HTML entities are escaped, so that it would not affect HTML. But this should not have side effects. Here is code snippet that makes string html safe:

    var htmlSafeString = suggestion.value
        .replace(/&/g, '&')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;');

I just tested sample with quotes, and quotes are displayed normally in the suggestion list.

@tkirda tkirda closed this as completed Jul 16, 2015
@arp242
Copy link

arp242 commented Jul 29, 2015

Hi, I seem have the same problem, the issue is the search highlighting is applied to the HTML entities, so for example searching for g gives us this HTML:

Mar<strong>t</strong>in &l<strong>t</strong>;mar<strong>t</strong>in@arp242.ne<strong>t</strong>&g<strong>t</strong>;

This is done in the Autocomplete.formatResult function. &l<strong>t</strong>; is obviously wrong.

Below is a patch which sort of fixes it, we escape HTML entities after adding the strong tags, and then un-escape the strong tags again. It's not a pretty solution, but in my case it's "good enough", and my mind doesn't offer a better solution right this minute...

Thanks ;-)

--- /home/martin/jquery.autocomplete.js 2015-07-29 13:43:50.658932570 +0200
+++ contrib/jquery.autocomplete.js      2015-07-29 13:51:17.808507767 +0200
@@ -127,15 +127,16 @@
    $.Autocomplete = Autocomplete;

    Autocomplete.formatResult = function (suggestion, currentValue) {
-        var htmlSafeString = suggestion.value
-            .replace(/&/g, '&amp;')
-            .replace(/</g, '&lt;')
-            .replace(/>/g, '&gt;')
-            .replace(/"/g, '&quot;');

        var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';

-        return htmlSafeString.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
+        return suggestion.value
+          .replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
+          .replace(/&/g, '&amp;')
+          .replace(/</g, '&lt;')
+          .replace(/>/g, '&gt;')
+          .replace(/"/g, '&quot;')
+          .replace(/&lt;(\/?strong)&gt;/g, '<$1>');
    };

    Autocomplete.prototype = {

Navarik-dev pushed a commit to Navarik-dev/jQuery-Autocomplete that referenced this issue Oct 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants