javascript - Angularjs ui utils highlight filter breaks application on search -
javascript - Angularjs ui utils highlight filter breaks application on search -
i using angular ui-utils highlight filter , have next code:
<span data-ng-bind-html="organization.level1name | highlight:vm.search"></span>
when search using special character [ or (, angular exception , application breaks.
syntaxerror: invalid regular expression: /(/: unterminated grouping @ new regexp (native) @ v. (http://localhost:50463/eia/source/dist/vendor.min.js:72:1157) @ (http://localhost:50463/eia/source/dist/vendor.min.js:38:92754) @ cr.| (http://localhost:50463/eia/source/dist/vendor.min.js:38:86832) @ h.constant (http://localhost:50463/eia/source/dist/vendor.min.js:38:92126) @ object.e (http://localhost:50463/eia/source/dist/vendor.min.js:38:101832) @ v.$digest (http://localhost:50463/eia/source/dist/vendor.min.js:38:57280) @ v.$apply (http://localhost:50463/eia/source/dist/vendor.min.js:38:58986) @ http://localhost:50463/eia/source/dist/client.js:1007:31 @ http://localhost:50463/eia/source/dist/vendor.min.js:38:64888 undefined
i tried using ng-sanitize library still same error.
please, how resolve that?
you should escape regexp input since (
special character regular expressions:
function escaperegexp(str) { homecoming str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); }
then, utilize it:
new regexp(escaperegexp(search), 'gi')
javascript regex angularjs angular-ui angularjs-ui-utils
Comments
Post a Comment