Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

RegExp stack trace if entering a tag with invalid regexp metacharacters #124

Closed
dennisjlee opened this issue Apr 11, 2014 · 2 comments
Closed

Comments

@dennisjlee
Copy link

Steps

  1. Set up an ng-tags-input with autocomplete (e.g. the "Simple tags input with autocomplete" example on the demo page http://mbenford.github.io/ngTagsInput/demos.html)
  2. Type a tag name containing "**" or other characters that constitute an invalid regexp

This will produce a JS error like below:

SyntaxError: Invalid regular expression: /a**b/: Nothing to repeat
    at new RegExp (native)
    at o (http://cdnjs.cloudflare.com/ajax/libs/ng-tags-input/2.0.0/ng-tags-input.min.js:1:5988)
    at Scope.b.highlight (http://cdnjs.cloudflare.com/ajax/libs/ng-tags-input/2.0.0/ng-tags-input.min.js:1:6233)
    at http://code.angularjs.org/1.2.15/angular.js:10348:21
    at Object.getStringValue (http://code.angularjs.org/1.2.15/angular.js:17668:41)
    at Scope.$digest (http://code.angularjs.org/1.2.15/angular.js:12023:40)
    at Scope.$apply (http://code.angularjs.org/1.2.15/angular.js:12279:24)
    at done (http://code.angularjs.org/1.2.15/angular.js:7991:45)
    at completeRequest (http://code.angularjs.org/1.2.15/angular.js:8196:7)
    at XMLHttpRequest.xhr.onreadystatechange (http://code.angularjs.org/1.2.15/angular.js:8137:11) 

This is due to the code below in the autoComplete directive - user-generated text should be escaped before being passed to RegExp.

 if (scope.options.highlightMatchedText) {
    markdown = function(item, text) {
        var expression = new RegExp(text, 'gi');
        return item.replace(expression, '**$&**');
   };
 }
@mbenford
Copy link
Owner

Hi @dennisjlee. Thanks for reporting that issue! 👍

@dennisjlee
Copy link
Author

Awesome, thanks for the quick fix!

On Sun, Apr 13, 2014 at 8:19 PM, Michael Benford
notifications@github.comwrote:

Closed #124 #124 via
e3c695fhttps://github.com/mbenford/ngTagsInput/commit/e3c695f26f96ab642a4a1f1129638e763b84b231
.

Reply to this email directly or view it on GitHubhttps://github.com//issues/124
.

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

No branches or pull requests

2 participants