list.js icon indicating copy to clipboard operation
list.js copied to clipboard

Searching for special characters like <,>,= fails in list.js search.

Open runwaldarshu opened this issue 12 years ago • 17 comments

Instead of actual characters lt; gt; is used it works.

runwaldarshu avatar Aug 19 '13 16:08 runwaldarshu

This issue can be fixed by adding conversion for following characters in list.js before performing the search:

  • '&' (ampersand) becomes '&'
  • '"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
  • "'" (single quote) becomes ''' (or ') only when ENT_QUOTES is set.
  • '<' (less than) becomes '<'
  • '>' (greater than) becomes '>'

I have tried a fix which works and following is the patch for it:

diff --git a/src/list.js b/src/list.js
index 44ce687..6ecf910 100644
--- a/src/list.js
+++ b/src/list.js
@@ -286,6 +286,18 @@ var List = function(id, options, values) {
         self.update();
     };

+    /**
+     * This method is helper method for replacing special characters to HTML entities.
+     */
+    function escapeHtml(text) {
+      return text
+          .replace(/&/g, "&amp;")
+          .replace(/</g, "&lt;")
+          .replace(/>/g, "&gt;")
+          .replace(/"/g, "&quot;")
+          .replace(/'/g, "&#039;");
+    }
+
     /*
     * Searches the list after values with content "searchStringOrEvent".
     * The columns parameter defines if all values should be included in the search,

runwaldarshu avatar Aug 19 '13 18:08 runwaldarshu

You can also find the changes @ https://github.com/runwaldarshu/listHtmlCharsFix/compare/master%40%7B1day%7D...master

runwaldarshu avatar Aug 19 '13 18:08 runwaldarshu

Oh, this looks interesting @runwaldarshu! I'll try implement, test and benchmark it as soon as possible.

javve avatar Aug 19 '13 20:08 javve

Are there any updates on this issue consideration?

runwaldarshu avatar Sep 20 '13 21:09 runwaldarshu

I also ran into an issue caused by this problem. Would be nice if we could put that in

nicam avatar Nov 06 '13 14:11 nicam

Has this / can it be implemented. Not being able to search for special characters is a deal-breaker for so many uses, including my list of songs (where I'm, I've, Love's, You're, You & Me, etc. are all the rage).

simonseddon avatar Apr 21 '15 10:04 simonseddon

I'm also hitting this issue, it's somewhat annoying that I can't use the CDN but have to use a "custom" version of list.js...

Here's how I modified list.js:

ben@ben-laptop:~/Music/soultalks$ diff -u list-unmodified.js list.js 
--- list-unmodified.js  2015-09-05 14:43:03.603620896 +0100
+++ list.js 2015-09-05 14:41:04.375623031 +0100
@@ -969,6 +969,12 @@
         setSearchString: function(s) {
             s = toString(s).toLowerCase();
             s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&"); // Escape regular expression characters
+            // Escape special characters
+            s = s.replace(/&/g, "&amp;")
+            s = s.replace(/</g, "&lt;")
+            s = s.replace(/>/g, "&gt;")
+            s = s.replace(/"/g, "&quot;")
+            s = s.replace(/'/g, "&#039;");
             searchString = s;
         },
         toArray: function(values) {

BenjaminEHowe avatar Sep 05 '15 12:09 BenjaminEHowe

See issue #327 for a solution which requires no modification to the script. It does however mean that special characters aren't searchable - as they're stripped out of both the search input AND searchable objects. Worked great for my use case.

simonseddon avatar Sep 05 '15 14:09 simonseddon

@javve this hasn't been implemented into the main library yet, right?

cbier avatar Dec 08 '15 15:12 cbier

No, list.js seems dead. I need it badly for one of my projects, but it seems I would need to fork it and add all the current pull requests.

wolffe avatar Dec 08 '15 15:12 wolffe

I am just modifying the library locally to add the things I need, maybe that will be a quicker solution for you @wolffe . For instance, these changes I am having to do myself.

cbier avatar Dec 08 '15 15:12 cbier

I have added lots of changes myself, but I would appreciate an official library.

wolffe avatar Dec 08 '15 15:12 wolffe

Yeah I definitely agree. I am grateful for this library but it's shortcomings seem so big sometimes. There are also great pull requests that have been waiting to be merged in.

I just hope that @javve is ok. Thanks for the library @javve.

cbier avatar Dec 09 '15 15:12 cbier

Wow, heh, I'm really sorry for my lack of updates around List.js :cold_sweat: ...and thanks a lot for the concern @cbier :relaxed:

I've been working with v1.2.0 for a while now and it's getting closer!

I tried to reproduce this error but I don't think I understand everything exactly. Here is a Codepen I made that includes ", ' and &. http://codepen.io/javve/pen/xVxZrw

For me it works if I search with for " and '. & works if I write Martina& but not if I write something after &. Weird.

How do you want it to work?

...and what browsers & os are you using?

javve avatar Feb 26 '16 21:02 javve

On that codepen, searching for tina&E should yield the obvious result :-)

Chrome 48 on Windows 10 Pro

BenjaminEHowe avatar Feb 27 '16 16:02 BenjaminEHowe

If I have any text like "A&B" and search with following cases

  1. Search A& : Works
  2. Search & : Works
  3. Search : A&B : Not working
  4. Search &B : Not working

So how to fix aboave issue ?

Er-Kalpesh avatar Nov 01 '16 09:11 Er-Kalpesh

in my case i changed setSearchString: function (e) { e = (e = t.utils.toString(e).toLowerCase()).replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&") to setSearchString: function (e) { e = (e = t.utils.toString(e).toLowerCase()).replace(/[-[\]{}()*+?.,\\^$|#]/g, "\$&") in min bundle. And now it works. I think, double escaping ruined search

avveshka avatar Feb 20 '25 09:02 avveshka