Browse Source

test matching update for optionals

Robin Herbots 10 years ago
parent
commit
d1a88c08f7

+ 1 - 0
CHANGELOG.md

@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
 - Add Component package manager support - component.json 
 - Add Component package manager support - component.json 
 
 
 ### Fixed
 ### Fixed
+- Sequentional optional parts do not fully match #699
 - How i fix that number problem? #835
 - How i fix that number problem? #835
 - Form reset doesn't get same value as initial mask #842
 - Form reset doesn't get same value as initial mask #842
 - Numeric extension doesn't seem to support min/max values #830
 - Numeric extension doesn't seem to support min/max values #830

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "jquery.inputmask",
   "name": "jquery.inputmask",
-  "version": "3.1.62-19",
+  "version": "3.1.62-26",
   "main": [
   "main": [
     "./dist/inputmask/jquery.inputmask.js",
     "./dist/inputmask/jquery.inputmask.js",
     "./dist/inputmask/jquery.inputmask.extensions.js",
     "./dist/inputmask/jquery.inputmask.extensions.js",

+ 1 - 1
component.json

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

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
 {
     "name": "robinherbots/jquery.inputmask",
     "name": "robinherbots/jquery.inputmask",
     "description": "jquery.inputmask is a jquery plugin which create an input mask.",
     "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-	"version": "3.1.62-19",
+	"version": "3.1.62-26",
     "type": "library",
     "type": "library",
     "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
     "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
     "homepage": "http://robinherbots.github.io/jquery.inputmask",
     "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
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-19
+* Version: 3.1.62-26
 */
 */
 !function(factory) {
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : 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
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-19
+* Version: 3.1.62-26
 */
 */
 !function(factory) {
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);

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


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

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-19
+* Version: 3.1.62-26
 */
 */
 !function(factory) {
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : factory(jQuery);
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : factory(jQuery);
@@ -234,13 +234,16 @@
                 var i, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), lvp = getLastValidPosition();
                 var i, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), lvp = getLastValidPosition();
                 for (i = pos; lvp >= i; i++) delete getMaskSet().validPositions[i];
                 for (i = pos; lvp >= i; i++) delete getMaskSet().validPositions[i];
                 getMaskSet().validPositions[pos] = validTest;
                 getMaskSet().validPositions[pos] = validTest;
-                var j, valid = !0;
-                for (i = pos; lvp >= i; i++) {
+                var j, valid = !0, vps = getMaskSet().validPositions;
+                for (i = j = pos; lvp >= i; i++) {
                     var t = positionsClone[i];
                     var t = positionsClone[i];
-                    if (void 0 != t) {
-                        var vps = getMaskSet().validPositions;
-                        j = !opts.keepStatic && vps[i] && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || void 0 != vps[i].alternation) ? i + 1 : seekNext(i), 
-                        valid = positionCanMatchDefinition(j, t.match.def) ? valid && isValid(j, t.input, !0, !0) !== !1 : null == t.match.fn;
+                    if (void 0 != t) for (var posMatch = j; posMatch < getMaskLength(); ) {
+                        if (null == t.match.fn || !opts.keepStatic && vps[i] && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || void 0 != vps[i].alternation) ? posMatch++ : posMatch = seekNext(j), 
+                        positionCanMatchDefinition(posMatch, t.match.def)) {
+                            valid = valid && isValid(posMatch, t.input, !0, !0) !== !1, j = posMatch;
+                            break;
+                        }
+                        valid = null == t.match.fn;
                     }
                     }
                     if (!valid) break;
                     if (!valid) break;
                 }
                 }
@@ -299,7 +302,8 @@
                             var optionalToken = match;
                             var optionalToken = match;
                             if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) {
                             if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) {
                                 var latestMatch = matches[matches.length - 1].match, isFirstMatch = 0 == $.inArray(latestMatch, optionalToken.matches);
                                 var latestMatch = matches[matches.length - 1].match, isFirstMatch = 0 == $.inArray(latestMatch, optionalToken.matches);
-                                isFirstMatch && (insertStop = !0), testPos = pos;
+                                if (!isFirstMatch) return !0;
+                                insertStop = !0, testPos = pos;
                             }
                             }
                         } else if (match.isAlternator) {
                         } else if (match.isAlternator) {
                             var maltMatches, alternateToken = match, malternateMatches = [], currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
                             var maltMatches, alternateToken = match, malternateMatches = [], currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -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
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-19
+* Version: 3.1.62-26
 */
 */
 !function(factory) {
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);

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


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

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

File diff suppressed because it is too large
+ 1 - 1
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
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-19
+* Version: 3.1.62-26
 */
 */
 !function(factory) {
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);

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


+ 12 - 8
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.62-19
+* Version: 3.1.62-26
 */
 */
 !function($) {
 !function($) {
     function isInputEventSupported(eventName) {
     function isInputEventSupported(eventName) {
@@ -232,13 +232,16 @@
                 var i, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), lvp = getLastValidPosition();
                 var i, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), lvp = getLastValidPosition();
                 for (i = pos; lvp >= i; i++) delete getMaskSet().validPositions[i];
                 for (i = pos; lvp >= i; i++) delete getMaskSet().validPositions[i];
                 getMaskSet().validPositions[pos] = validTest;
                 getMaskSet().validPositions[pos] = validTest;
-                var j, valid = !0;
-                for (i = pos; lvp >= i; i++) {
+                var j, valid = !0, vps = getMaskSet().validPositions;
+                for (i = j = pos; lvp >= i; i++) {
                     var t = positionsClone[i];
                     var t = positionsClone[i];
-                    if (void 0 != t) {
-                        var vps = getMaskSet().validPositions;
-                        j = !opts.keepStatic && vps[i] && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || void 0 != vps[i].alternation) ? i + 1 : seekNext(i), 
-                        valid = positionCanMatchDefinition(j, t.match.def) ? valid && isValid(j, t.input, !0, !0) !== !1 : null == t.match.fn;
+                    if (void 0 != t) for (var posMatch = j; posMatch < getMaskLength(); ) {
+                        if (null == t.match.fn || !opts.keepStatic && vps[i] && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || void 0 != vps[i].alternation) ? posMatch++ : posMatch = seekNext(j), 
+                        positionCanMatchDefinition(posMatch, t.match.def)) {
+                            valid = valid && isValid(posMatch, t.input, !0, !0) !== !1, j = posMatch;
+                            break;
+                        }
+                        valid = null == t.match.fn;
                     }
                     }
                     if (!valid) break;
                     if (!valid) break;
                 }
                 }
@@ -297,7 +300,8 @@
                             var optionalToken = match;
                             var optionalToken = match;
                             if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) {
                             if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) {
                                 var latestMatch = matches[matches.length - 1].match, isFirstMatch = 0 == $.inArray(latestMatch, optionalToken.matches);
                                 var latestMatch = matches[matches.length - 1].match, isFirstMatch = 0 == $.inArray(latestMatch, optionalToken.matches);
-                                isFirstMatch && (insertStop = !0), testPos = pos;
+                                if (!isFirstMatch) return !0;
+                                insertStop = !0, testPos = pos;
                             }
                             }
                         } else if (match.isAlternator) {
                         } else if (match.isAlternator) {
                             var maltMatches, alternateToken = match, malternateMatches = [], currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
                             var maltMatches, alternateToken = match, malternateMatches = [], currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;

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


+ 21 - 14
js/jquery.inputmask.js

@@ -395,19 +395,25 @@
                         delete getMaskSet()["validPositions"][i];
                         delete getMaskSet()["validPositions"][i];
                     }
                     }
                     getMaskSet()["validPositions"][pos] = validTest;
                     getMaskSet()["validPositions"][pos] = validTest;
-                    var valid = true, j;
-                    for (i = pos; i <= lvp ; i++) {
+                    var valid = true, j, vps = getMaskSet()["validPositions"];
+                    for (i = (j = pos) ; i <= lvp ; i++) {
                         var t = positionsClone[i];
                         var t = positionsClone[i];
                         if (t != undefined) {
                         if (t != undefined) {
-                            var vps = getMaskSet()["validPositions"];
-                            if (!opts.keepStatic && vps[i] && (vps[i + 1] != undefined && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || vps[i].alternation != undefined))
-                                j = i + 1;
-                            else
-                                j = seekNext(i);
-
-                            if (positionCanMatchDefinition(j, t["match"].def)) {
-                                valid = valid && (isValid(j, t["input"], true, true) !== false);
-                            } else valid = t["match"].fn == null;
+                            var posMatch = j;
+                            while (posMatch < getMaskLength()) {
+                                //determine next position
+                                if (t.match.fn == null || (!opts.keepStatic && vps[i] && (vps[i + 1] != undefined && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || vps[i].alternation != undefined)))
+                                    posMatch++;
+                                else
+                                    posMatch = seekNext(j);
+
+                                //does it match
+                                if (positionCanMatchDefinition(posMatch, t["match"].def)) {
+                                    valid = valid && (isValid(posMatch, t["input"], true, true) !== false);
+                                    j = posMatch;
+                                    break;
+                                } else valid = t["match"].fn == null;
+                            }
                         }
                         }
                         if (!valid) break;
                         if (!valid) break;
                     }
                     }
@@ -523,8 +529,8 @@
                                     var isFirstMatch = $.inArray(latestMatch, optionalToken.matches) == 0;
                                     var isFirstMatch = $.inArray(latestMatch, optionalToken.matches) == 0;
                                     if (isFirstMatch) {
                                     if (isFirstMatch) {
                                         insertStop = true; //insert a stop
                                         insertStop = true; //insert a stop
-                                    }
-                                    testPos = pos; //match the position after the group
+                                        testPos = pos; //match the position after the group
+                                    } else return true;
                                 }
                                 }
                             } else if (match.isAlternator) {
                             } else if (match.isAlternator) {
                                 var alternateToken = match, malternateMatches = [], maltMatches,
                                 var alternateToken = match, malternateMatches = [], maltMatches,
@@ -727,6 +733,7 @@
 
 
                 function _isValid(position, c, strict, fromSetValid) {
                 function _isValid(position, c, strict, fromSetValid) {
                     var rslt = false;
                     var rslt = false;
+                    //console.log(JSON.stringify(getTests(position)));
                     $.each(getTests(position), function (ndx, tst) {
                     $.each(getTests(position), function (ndx, tst) {
                         var test = tst["match"];
                         var test = tst["match"];
                         var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
                         var loopend = c ? 1 : 0, chrs = '', buffer = getBuffer();
@@ -1318,7 +1325,7 @@
 
 
                 if (!npt._valueGet) {
                 if (!npt._valueGet) {
                     var valueProperty;
                     var valueProperty;
-                    if (Object.getOwnPropertyDescriptor && npt.value == undefined){ // && npt.isContentEditable) {
+                    if (Object.getOwnPropertyDescriptor && npt.value == undefined) { // && npt.isContentEditable) {
                         valueGet = function () {
                         valueGet = function () {
                             return this.textContent;
                             return this.textContent;
                         }
                         }

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "jquery.inputmask",
   "name": "jquery.inputmask",
-  "version": "3.1.62-19",
+  "version": "3.1.62-26",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "main": "./dist/inputmask/jquery.inputmask.js",
   "main": "./dist/inputmask/jquery.inputmask.js",
   "scripts": {
   "scripts": {

+ 12 - 0
qunit/tests_optional.js

@@ -246,4 +246,16 @@ test(".inputmask('999-999-9999[ ext 9{1,5}]'); - type 12345678901 backspace isco
     equal($("#testmask").inputmask("isComplete"), true, "Result " + $("#testmask").inputmask("isComplete"));
     equal($("#testmask").inputmask("isComplete"), true, "Result " + $("#testmask").inputmask("isComplete"));
 
 
     $("#testmask").remove();
     $("#testmask").remove();
+});
+
+test("inputmask({ mask: \"9999[ 9999][ 9999]\"}) - input 1234 space space - GMTA", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: "9999[ 9999][ 9999]"});
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("1234  ");
+    equal($("#testmask").val(), "1234 ____ ____", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
 });
 });