Searching for special characters like <,>,= fails in list.js search.
Instead of actual characters lt; gt; is used it works.
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, "&")
+ .replace(/</g, "<")
+ .replace(/>/g, ">")
+ .replace(/"/g, """)
+ .replace(/'/g, "'");
+ }
+
/*
* Searches the list after values with content "searchStringOrEvent".
* The columns parameter defines if all values should be included in the search,
You can also find the changes @ https://github.com/runwaldarshu/listHtmlCharsFix/compare/master%40%7B1day%7D...master
Oh, this looks interesting @runwaldarshu! I'll try implement, test and benchmark it as soon as possible.
Are there any updates on this issue consideration?
I also ran into an issue caused by this problem. Would be nice if we could put that in
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).
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, "&")
+ s = s.replace(/</g, "<")
+ s = s.replace(/>/g, ">")
+ s = s.replace(/"/g, """)
+ s = s.replace(/'/g, "'");
searchString = s;
},
toArray: function(values) {
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.
@javve this hasn't been implemented into the main library yet, right?
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.
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.
I have added lots of changes myself, but I would appreciate an official library.
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.
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?
On that codepen, searching for tina&E should yield the obvious result :-)
Chrome 48 on Windows 10 Pro
If I have any text like "A&B" and search with following cases
- Search A& : Works
- Search & : Works
- Search : A&B : Not working
- Search &B : Not working
So how to fix aboave issue ?
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