Browse Source

fix alternators length mismatch

Robin Herbots 10 years ago
parent
commit
0aa81231ce

+ 0 - 1
CHANGELOG.md

@@ -4,7 +4,6 @@ All notable changes to this project will be documented in this file.
 ## [unpublished]
 ### Added
 - Support for CommonJS (Browserify)
->>>>>>> e251ca4897ef891c47ae99ab9b90b2e65ce67e85
 
 ## [3.1.62] - 2015-03-26
 ### Added

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.1.63-2",
+  "version": "3.1.63-7",
   "main": [
     "./dist/inputmask/jquery.inputmask.js",
     "./dist/inputmask/jquery.inputmask.extensions.js",

+ 1 - 1
component.json

@@ -2,7 +2,7 @@
     "name": "jquery_inputmask",
     "repository": "robinherbots/jquery.inputmask",
     "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-    "version": "3.1.63-2",
+    "version": "3.1.63-7",
     "keywords": [ "jquery", "plugins", "input", "form", "inputmask", "mask" ],
     "main": "./dist/jquery.inputmask.bundle.js",
     "scripts": [

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
     "name": "robinherbots/jquery.inputmask",
     "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-	"version": "3.1.63-2",
+	"version": "3.1.63-7",
     "type": "library",
     "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
     "homepage": "http://robinherbots.github.io/jquery.inputmask",

+ 1 - 1
dist/inputmask/jquery.inputmask.date.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.63-2
+* Version: 3.1.63-7
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

File diff suppressed because it is too large
+ 1 - 1
dist/inputmask/jquery.inputmask.date.extensions.min.js


+ 1 - 1
dist/inputmask/jquery.inputmask.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.63-2
+* Version: 3.1.63-7
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

File diff suppressed because it is too large
+ 1 - 1
dist/inputmask/jquery.inputmask.extensions.min.js


+ 11 - 12
dist/inputmask/jquery.inputmask.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.63-2
+* Version: 3.1.63-7
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);
@@ -204,9 +204,8 @@
                 if (baseOnInput === !0 && getMaskSet().validPositions[pos]) {
                     var validPos = getMaskSet().validPositions[pos];
                     test = validPos.match, ndxIntlzr = validPos.locator.slice(), maskTemplate.push(includeInput === !0 ? validPos.input : getPlaceholder(pos, test));
-                } else console.log("getmasktemplate " + pos + " " + JSON.stringify(ndxIntlzr)), 
-                testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), test = testPos.match, ndxIntlzr = testPos.locator.slice(), 
-                maskTemplate.push(getPlaceholder(pos, test));
+                } else testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), test = testPos.match, 
+                ndxIntlzr = testPos.locator.slice(), maskTemplate.push(getPlaceholder(pos, test));
                 pos++;
             } while ((void 0 == maxLength || maxLength > pos - 1) && null != test.fn || null == test.fn && "" != test.def || minimalPos >= pos);
             return maskTemplate.pop(), maskTemplate;
@@ -273,7 +272,7 @@
         }
         function getTestTemplate(pos, ndxIntlzr, tstPs) {
             var testPos = getMaskSet().validPositions[pos];
-            if (void 0 == testPos) for (var testPositions = getTests(pos, ndxIntlzr, tstPs), lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0, void 0, void 0)[0], lvTestAltArr = void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].toString().split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx], 
+            if (void 0 == testPos) for (var testPositions = getTests(pos, ndxIntlzr, tstPs), lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0)[0], lvTestAltArr = void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].toString().split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx], 
             !(testPos.match && (opts.greedy && testPos.match.optionalQuantifier !== !0 || (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0) && (void 0 == lvTest.alternation || lvTest.alternation != testPos.alternation || void 0 != testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr)))); ndx++) ;
             return testPos;
         }
@@ -313,12 +312,12 @@
                                 "string" == typeof altIndex && (altIndexArr = altIndex.split(","));
                                 for (var amndx = 0; amndx < alternateToken.matches.length; amndx++) {
                                     if (matches = [], match = handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse) || match, 
-                                    match !== !0) {
+                                    match !== !0 && void 0 != match && altIndexArr[altIndexArr.length - 1] < alternateToken.matches.length) {
                                         var ntndx = maskToken.matches.indexOf(match) + 1;
-                                        match = handleMatch(maskToken.matches[ntndx], [ ntndx ].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse), 
+                                        maskToken.matches.length > ntndx && (match = handleMatch(maskToken.matches[ntndx], [ ntndx ].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse), 
                                         match && (altIndexArr.push(ntndx.toString()), $.each(matches, function(ndx, lmnt) {
                                             lmnt.alternation = loopNdx.length - 1;
-                                        }));
+                                        })));
                                     }
                                     maltMatches = matches.slice(), testPos = currentPos, matches = [];
                                     for (var i = 0; i < ndxInitializerClone.length; i++) ndxInitializer[i] = ndxInitializerClone[i];
@@ -328,7 +327,7 @@
                                         for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
                                             var altMatch2 = malternateMatches[ndx2];
                                             if (altMatch.match.mask == altMatch2.match.mask && ("string" != typeof altIndex || -1 != $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr))) {
-                                                maltMatches.splice(ndx1, 1), altMatch2.locator[altMatch.alternation] = altMatch2.locator[altMatch.alternation] + "," + altMatch.locator[altMatch.alternation], 
+                                                maltMatches.splice(ndx1, 1), ndx1--, altMatch2.locator[altMatch.alternation] = altMatch2.locator[altMatch.alternation] + "," + altMatch.locator[altMatch.alternation], 
                                                 altMatch2.alternation = altMatch.alternation;
                                                 break;
                                             }
@@ -346,7 +345,7 @@
                                         lmnt.alternation = alternation);
                                         if (void 0 != lmnt.locator[alternation]) return lmnt;
                                     }
-                                })), matches = currentMatches.concat(malternateMatches), testPos = pos, insertStop = !0;
+                                })), matches = currentMatches.concat(malternateMatches), testPos = pos, insertStop = matches.length > 0;
                             } else match = alternateToken.matches[altIndex] ? handleMatch(alternateToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse) : !1;
                             if (match) return !0;
                         } else if (match.isQuantifier && quantifierRecurse !== !0) for (var qt = match, qndx = ndxInitializer.length > 0 && quantifierRecurse !== !0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && pos >= testPos; qndx++) {
@@ -374,6 +373,7 @@
                 }
             }
             var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [ 0 ], matches = [], insertStop = !1;
+            if (cacheable === !0 && getMaskSet().tests[pos]) return getMaskSet().tests[pos];
             if (void 0 == ndxIntlzr) {
                 for (var test, previousPos = pos - 1; void 0 == (test = getMaskSet().validPositions[previousPos]) && previousPos > -1; ) previousPos--;
                 if (void 0 != test && previousPos > -1) testPos = previousPos, ndxInitializer = test.locator.slice(); else {
@@ -394,8 +394,7 @@
                     def: ""
                 },
                 locator: []
-            }), getMaskSet().tests[pos] = $.extend(!0, [], matches), console.log(pos + " - " + JSON.stringify(matches)), 
-            getMaskSet().tests[pos];
+            }), getMaskSet().tests[pos] = $.extend(!0, [], matches), getMaskSet().tests[pos];
         }
         function getBufferTemplate() {
             return void 0 == getMaskSet()._buffer && (getMaskSet()._buffer = getMaskTemplate(!1, 1)), 

File diff suppressed because it is too large
+ 2 - 2
dist/inputmask/jquery.inputmask.min.js


+ 1 - 1
dist/inputmask/jquery.inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.63-2
+* Version: 3.1.63-7
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

File diff suppressed because it is too large
+ 1 - 1
dist/inputmask/jquery.inputmask.numeric.extensions.min.js


+ 4 - 16
dist/inputmask/jquery.inputmask.phone.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.63-2
+* Version: 3.1.63-7
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);
@@ -11,21 +11,9 @@
     return $.extend($.inputmask.defaults.aliases, {
         phone: {
             url: "phone-codes/phone-codes.js",
-            maskInit: "+pp(pp)pppppppp",
             countrycode: "",
             mask: function(opts) {
-                opts.definitions = {
-                    p: {
-                        validator: function() {
-                            return !1;
-                        },
-                        cardinality: 1
-                    },
-                    "#": {
-                        validator: "[0-9]",
-                        cardinality: 1
-                    }
-                };
+                opts.definitions["#"] = opts.definitions[9];
                 var maskList = [];
                 return $.ajax({
                     url: opts.url,
@@ -39,9 +27,9 @@
                     }
                 }), maskList = maskList.sort(function(a, b) {
                     return (a.mask || a) < (b.mask || b) ? -1 : 1;
-                }), "" != opts.countrycode && (opts.maskInit = "+" + opts.countrycode + opts.maskInit.substring(3)), 
-                maskList.splice(0, 0, opts.maskInit), maskList;
+                });
             },
+            keepStatic: !1,
             nojumps: !0,
             nojumpsThreshold: 1,
             onBeforeMask: function(value, opts) {

File diff suppressed because it is too large
+ 2 - 2
dist/inputmask/jquery.inputmask.phone.extensions.min.js


+ 1 - 1
dist/inputmask/jquery.inputmask.regex.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.63-2
+* Version: 3.1.63-7
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

File diff suppressed because it is too large
+ 1 - 1
dist/inputmask/jquery.inputmask.regex.extensions.min.js


+ 14 - 27
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.63-2
+* Version: 3.1.63-7
 */
 !function($) {
     function isInputEventSupported(eventName) {
@@ -202,9 +202,8 @@
                 if (baseOnInput === !0 && getMaskSet().validPositions[pos]) {
                     var validPos = getMaskSet().validPositions[pos];
                     test = validPos.match, ndxIntlzr = validPos.locator.slice(), maskTemplate.push(includeInput === !0 ? validPos.input : getPlaceholder(pos, test));
-                } else console.log("getmasktemplate " + pos + " " + JSON.stringify(ndxIntlzr)), 
-                testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), test = testPos.match, ndxIntlzr = testPos.locator.slice(), 
-                maskTemplate.push(getPlaceholder(pos, test));
+                } else testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), test = testPos.match, 
+                ndxIntlzr = testPos.locator.slice(), maskTemplate.push(getPlaceholder(pos, test));
                 pos++;
             } while ((void 0 == maxLength || maxLength > pos - 1) && null != test.fn || null == test.fn && "" != test.def || minimalPos >= pos);
             return maskTemplate.pop(), maskTemplate;
@@ -271,7 +270,7 @@
         }
         function getTestTemplate(pos, ndxIntlzr, tstPs) {
             var testPos = getMaskSet().validPositions[pos];
-            if (void 0 == testPos) for (var testPositions = getTests(pos, ndxIntlzr, tstPs), lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0, void 0, void 0)[0], lvTestAltArr = void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].toString().split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx], 
+            if (void 0 == testPos) for (var testPositions = getTests(pos, ndxIntlzr, tstPs), lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0)[0], lvTestAltArr = void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].toString().split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx], 
             !(testPos.match && (opts.greedy && testPos.match.optionalQuantifier !== !0 || (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0) && (void 0 == lvTest.alternation || lvTest.alternation != testPos.alternation || void 0 != testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAltArr)))); ndx++) ;
             return testPos;
         }
@@ -311,12 +310,12 @@
                                 "string" == typeof altIndex && (altIndexArr = altIndex.split(","));
                                 for (var amndx = 0; amndx < alternateToken.matches.length; amndx++) {
                                     if (matches = [], match = handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse) || match, 
-                                    match !== !0) {
+                                    match !== !0 && void 0 != match && altIndexArr[altIndexArr.length - 1] < alternateToken.matches.length) {
                                         var ntndx = maskToken.matches.indexOf(match) + 1;
-                                        match = handleMatch(maskToken.matches[ntndx], [ ntndx ].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse), 
+                                        maskToken.matches.length > ntndx && (match = handleMatch(maskToken.matches[ntndx], [ ntndx ].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse), 
                                         match && (altIndexArr.push(ntndx.toString()), $.each(matches, function(ndx, lmnt) {
                                             lmnt.alternation = loopNdx.length - 1;
-                                        }));
+                                        })));
                                     }
                                     maltMatches = matches.slice(), testPos = currentPos, matches = [];
                                     for (var i = 0; i < ndxInitializerClone.length; i++) ndxInitializer[i] = ndxInitializerClone[i];
@@ -326,7 +325,7 @@
                                         for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
                                             var altMatch2 = malternateMatches[ndx2];
                                             if (altMatch.match.mask == altMatch2.match.mask && ("string" != typeof altIndex || -1 != $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr))) {
-                                                maltMatches.splice(ndx1, 1), altMatch2.locator[altMatch.alternation] = altMatch2.locator[altMatch.alternation] + "," + altMatch.locator[altMatch.alternation], 
+                                                maltMatches.splice(ndx1, 1), ndx1--, altMatch2.locator[altMatch.alternation] = altMatch2.locator[altMatch.alternation] + "," + altMatch.locator[altMatch.alternation], 
                                                 altMatch2.alternation = altMatch.alternation;
                                                 break;
                                             }
@@ -344,7 +343,7 @@
                                         lmnt.alternation = alternation);
                                         if (void 0 != lmnt.locator[alternation]) return lmnt;
                                     }
-                                })), matches = currentMatches.concat(malternateMatches), testPos = pos, insertStop = !0;
+                                })), matches = currentMatches.concat(malternateMatches), testPos = pos, insertStop = matches.length > 0;
                             } else match = alternateToken.matches[altIndex] ? handleMatch(alternateToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse) : !1;
                             if (match) return !0;
                         } else if (match.isQuantifier && quantifierRecurse !== !0) for (var qt = match, qndx = ndxInitializer.length > 0 && quantifierRecurse !== !0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && pos >= testPos; qndx++) {
@@ -372,6 +371,7 @@
                 }
             }
             var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [ 0 ], matches = [], insertStop = !1;
+            if (cacheable === !0 && getMaskSet().tests[pos]) return getMaskSet().tests[pos];
             if (void 0 == ndxIntlzr) {
                 for (var test, previousPos = pos - 1; void 0 == (test = getMaskSet().validPositions[previousPos]) && previousPos > -1; ) previousPos--;
                 if (void 0 != test && previousPos > -1) testPos = previousPos, ndxInitializer = test.locator.slice(); else {
@@ -392,8 +392,7 @@
                     def: ""
                 },
                 locator: []
-            }), getMaskSet().tests[pos] = $.extend(!0, [], matches), console.log(pos + " - " + JSON.stringify(matches)), 
-            getMaskSet().tests[pos];
+            }), getMaskSet().tests[pos] = $.extend(!0, [], matches), getMaskSet().tests[pos];
         }
         function getBufferTemplate() {
             return void 0 == getMaskSet()._buffer && (getMaskSet()._buffer = getMaskTemplate(!1, 1)), 
@@ -2251,21 +2250,9 @@
     return $.extend($.inputmask.defaults.aliases, {
         phone: {
             url: "phone-codes/phone-codes.js",
-            maskInit: "+pp(pp)pppppppp",
             countrycode: "",
             mask: function(opts) {
-                opts.definitions = {
-                    p: {
-                        validator: function() {
-                            return !1;
-                        },
-                        cardinality: 1
-                    },
-                    "#": {
-                        validator: "[0-9]",
-                        cardinality: 1
-                    }
-                };
+                opts.definitions["#"] = opts.definitions[9];
                 var maskList = [];
                 return $.ajax({
                     url: opts.url,
@@ -2279,9 +2266,9 @@
                     }
                 }), maskList = maskList.sort(function(a, b) {
                     return (a.mask || a) < (b.mask || b) ? -1 : 1;
-                }), "" != opts.countrycode && (opts.maskInit = "+" + opts.countrycode + opts.maskInit.substring(3)), 
-                maskList.splice(0, 0, opts.maskInit), maskList;
+                });
             },
+            keepStatic: !1,
             nojumps: !0,
             nojumpsThreshold: 1,
             onBeforeMask: function(value, opts) {

File diff suppressed because it is too large
+ 3 - 3
dist/jquery.inputmask.bundle.min.js


+ 18 - 17
js/jquery.inputmask.js

@@ -338,8 +338,6 @@
                 firstClick = true;
 
             //maskset helperfunctions
-
-
             function getMaskTemplate(baseOnInput, minimalPos, includeInput) {
                 minimalPos = minimalPos || 0;
                 var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos;
@@ -350,7 +348,7 @@
                         ndxIntlzr = validPos["locator"].slice();
                         maskTemplate.push(includeInput === true ? validPos["input"] : getPlaceholder(pos, test));
                     } else {
-                        console.log("getmasktemplate " + pos + " " + JSON.stringify(ndxIntlzr));
+                        //console.log("getmasktemplate " + pos + " " + JSON.stringify(ndxIntlzr));
                         testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
                         test = testPos["match"];
                         ndxIntlzr = testPos["locator"].slice();
@@ -469,12 +467,12 @@
 
                 resetMaskSet(true);
             }
-            function getTestTemplate(pos, ndxIntlzr, tstPs) {  //needs FIX TODO
+            function getTestTemplate(pos, ndxIntlzr, tstPs) {
                 var testPos = getMaskSet()["validPositions"][pos];
                 if (testPos == undefined) {
                     var testPositions = getTests(pos, ndxIntlzr, tstPs),
                         lvp = getLastValidPosition(),
-                        lvTest = getMaskSet()["validPositions"][lvp] || getTests(0, undefined, undefined)[0],
+                        lvTest = getMaskSet()["validPositions"][lvp] || getTests(0)[0],
                         lvTestAltArr = (lvTest.alternation != undefined) ? lvTest["locator"][lvTest.alternation].toString().split(',') : [];
                     for (var ndx = 0; ndx < testPositions.length; ndx++) {
                         testPos = testPositions[ndx];
@@ -543,17 +541,19 @@
                                 if (altIndex == -1 || typeof altIndex == "string") {
                                     var currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [];
                                     if (typeof altIndex == "string") altIndexArr = altIndex.split(",");
-                                    for (var amndx = 0; amndx < alternateToken.matches.length; amndx++) {
+                                    for (var amndx = 0; amndx < alternateToken.matches.length ; amndx++) {
                                         matches = [];
                                         match = handleMatch(alternateToken.matches[amndx], [amndx].concat(loopNdx), quantifierRecurse) || match;
-                                        if (match !== true) { //no match in the alternations (length mismatch) => look further
+                                        if (match !== true && match != undefined && (altIndexArr[altIndexArr.length - 1] < alternateToken.matches.length)) { //no match in the alternations (length mismatch) => look further
                                             var ntndx = maskToken.matches.indexOf(match) + 1;
-                                            match = handleMatch(maskToken.matches[ntndx], [ntndx].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse)
-                                            if (match) {
-                                                altIndexArr.push(ntndx.toString());
-                                                $.each(matches, function (ndx, lmnt) {
-                                                    lmnt.alternation = loopNdx.length - 1;
-                                                });
+                                            if (maskToken.matches.length > ntndx) {
+                                                match = handleMatch(maskToken.matches[ntndx], [ntndx].concat(loopNdx.slice(1, loopNdx.length)), quantifierRecurse)
+                                                if (match) {
+                                                    altIndexArr.push(ntndx.toString());
+                                                    $.each(matches, function (ndx, lmnt) {
+                                                        lmnt.alternation = loopNdx.length - 1;
+                                                    });
+                                                }
                                             }
                                         }
                                         maltMatches = matches.slice();
@@ -571,7 +571,7 @@
                                                 var altMatch2 = malternateMatches[ndx2];
                                                 //verify equality
                                                 if (altMatch.match.mask == altMatch2.match.mask && (typeof altIndex != "string" || $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr) != -1)) {
-                                                    maltMatches.splice(ndx1, 1);
+                                                    maltMatches.splice(ndx1, 1); ndx1--;
                                                     altMatch2.locator[altMatch.alternation] = altMatch2.locator[altMatch.alternation] + "," + altMatch.locator[altMatch.alternation];
                                                     altMatch2.alternation = altMatch.alternation; //we pass the alternation index => used in determineLastRequiredPosition
                                                     break;
@@ -608,7 +608,7 @@
 
                                     matches = currentMatches.concat(malternateMatches);
                                     testPos = pos;
-                                    insertStop = true; //insert a stopelemnt when there is an alternate
+                                    insertStop = matches.length > 0; //insert a stopelemnt when there is an alternate
                                 } else {
                                     if (alternateToken.matches[altIndex]) { //if not in the initial alternation => look further
                                         match = handleMatch(alternateToken.matches[altIndex], [altIndex].concat(loopNdx), quantifierRecurse);
@@ -657,7 +657,7 @@
                     }
                 }
 
-                if (false && cacheable !== false && getMaskSet()['tests'][pos]) {
+                if (cacheable === true && getMaskSet()['tests'][pos]) {
                     return getMaskSet()['tests'][pos];
                 }
                 if (ndxIntlzr == undefined) {
@@ -689,7 +689,8 @@
                     matches.push({ "match": { fn: null, cardinality: 0, optionality: true, casing: null, def: "" }, "locator": [] });
 
                 getMaskSet()['tests'][pos] = $.extend(true, [], matches); //set a clone to prevent overwriting some props
-                console.log(pos + " - " + JSON.stringify(matches));
+
+                //console.log(pos + " - " + JSON.stringify(matches));
                 return getMaskSet()['tests'][pos];
             }
             function getBufferTemplate() {

+ 2 - 15
js/jquery.inputmask.phone.extensions.js

@@ -21,19 +21,9 @@ When using this extension make sure you specify the correct url to get the masks
     $.extend($.inputmask.defaults.aliases, {
         'phone': {
             url: "phone-codes/phone-codes.js",
-            maskInit: "+pp(pp)pppppppp",
             countrycode: "",
             mask: function (opts) {
-                opts.definitions = {
-                    'p': {
-                        validator: function () { return false; },
-                        cardinality: 1
-                    },
-                    '#': {
-                        validator: "[0-9]",
-                        cardinality: 1
-                    }
-                };
+                opts.definitions['#'] = opts.definitions['9'];
                 var maskList = [];
                 $.ajax({
                     url: opts.url,
@@ -51,12 +41,9 @@ When using this extension make sure you specify the correct url to get the masks
                     return (a["mask"] || a) < (b["mask"] || b) ? -1 : 1;
                 });
 
-                if (opts.countrycode != "") {
-                    opts.maskInit = "+" + opts.countrycode + opts.maskInit.substring(3);
-                }
-                maskList.splice(0, 0, opts.maskInit);
                 return maskList;
             },
+            keepStatic: false,
             nojumps: true,
             nojumpsThreshold: 1,
             onBeforeMask: function (value, opts) {

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.1.63-2",
+  "version": "3.1.63-7",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "main": "./dist/inputmask/jquery.inputmask.js",
   "files": [

+ 12 - 2
qunit/tests_keepStatic.js

@@ -35,10 +35,10 @@ test("{ mask: ['(99) 9999-9999', '(99) 99999-9999'] } - val('1212341234')", func
     $("#testmask").remove();
 });
 
-test("{ mask: \"+55-99-9999|(99)-9999\", keepStatic: true } type 12123451234", function () {
+test("{ mask: \"+55-99-9999|(99)-9999\", keepStatic: false } type 12123451234", function () {
     var $fixture = $("#qunit-fixture");
     $fixture.append('<input type="text" id="testmask" />');
-    $("#testmask").inputmask({ mask: "+55-99-9999|(99)-9999", keepStatic: true });
+    $("#testmask").inputmask({ mask: "+55-99-9999|(99)-9999", keepStatic: false });
     $("#testmask")[0].focus();
     $("#testmask").Type("12123451234");
 
@@ -140,4 +140,14 @@ test("(78)|(74) 999 99 99", function () {
     equal(document.getElementById("testmask")._valueGet(), "7_ ___ __ __", "Result " + document.getElementById("testmask")._valueGet());
 
     $("#testmask").remove();
+});
+
+test("5-9|(9a)-5 - keepstatic: false", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: "5-9|(9a)-5", keepStatic: false });
+    $("#testmask")[0].focus();
+    equal(document.getElementById("testmask")._valueGet(), "5-_-5", "Result " + document.getElementById("testmask")._valueGet());
+
+    $("#testmask").remove();
 });