Angular ng-pattern browser crash

We have a regular expression that we use for email. Our application inherits a regular expression, so there may not be an option for switching it ... Anyway, the same set of steps seems to break javascript in the browser. I was able to reproduce in IE and Chrome, but not in Firefox. Here is the code:

var mod = angular.module("myApp", []);

mod.controller("MainCtrl", function ($scope) {
    //Pattern that blows up the browser during ng-pattern
    $scope.emailPattern = /^(?!.*\.{2})([a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+([\.][a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*)@((([\-]?[a-zA-Z0-9]){2,}[\.])*(([a-zA-Z0-9][\-]?){1,})+).(([\.]([a-zA-Z0-9][\-]?){2,}([a-zA-Z0-9])*)+)$/;


});

HTML:

<div ng-app="myApp" ng-controller="MainCtrl">
    <form name="emailForm" novalidate>
        <input type="text" ng-model="user.email" name="email" maxlength="80" required ng-pattern="emailPattern">
    </form>
    <br>
    {{user.email}}
</div>

Here is the script . Here are the basic steps that will lead to a browser crash:

  • Enter a bunch of alpha characters in the text box until it is full (other inputs may work, but this is what I used).
  • Returns 2 characters.
  • Press the Home key to return to the beginning of the entry.
  • Enter the characters: a @

IE Chrome. - ? ?

+4
1

, .

(, http://regexpal.com/), , ( ).


:

$scope.emailPattern = /^(?!.*\.{2})([a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+([\.][a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*)@((([\-]?[a-zA-Z0-9]){2,}[\.])*(([a-zA-Z0-9][\-]?){1,})+).(([\.]([a-zA-Z0-9][\-]?){2,}([a-zA-Z0-9])*)+)$/;

To:

$scope.emailPattern = /^(?!.*\.{2})([a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+([\.][a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*)@((([\-]?[a-zA-Z0-9]){2,}[\.])*(([a-zA-Z0-9][\-]?))+).(([\.]([a-zA-Z0-9][\-]?){2,}([a-zA-Z0-9])*)+)$/;
+5

Source: https://habr.com/ru/post/1533611/


All Articles