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

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

Open
runwaldarshu opened this issue Aug 19, 2013 · 16 comments
Open

Comments

@runwaldarshu
Copy link

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

@runwaldarshu
Copy link
Author

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
Copy link
Author

You can also find the changes @ runwaldarshu/listHtmlCharsFix@master@{1day}...master

@javve
Copy link
Owner

javve commented Aug 19, 2013

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

@runwaldarshu
Copy link
Author

Are there any updates on this issue consideration?

@nicam
Copy link

nicam commented Nov 6, 2013

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

@simonseddon
Copy link

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).

@BenjaminEHowe
Copy link

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) {

@simonseddon
Copy link

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.

@cbier
Copy link

cbier commented Dec 8, 2015

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

@wolffe
Copy link

wolffe commented Dec 8, 2015

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.

@cbier
Copy link

cbier commented Dec 8, 2015

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.

@wolffe
Copy link

wolffe commented Dec 8, 2015

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

@cbier
Copy link

cbier commented Dec 9, 2015

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.

@javve
Copy link
Owner

javve commented Feb 26, 2016

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

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?

@BenjaminEHowe
Copy link

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

Chrome 48 on Windows 10 Pro

@Er-Kalpesh
Copy link

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 ?

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

No branches or pull requests

8 participants