Skip to content

Commit 114fa18

Browse files
committed
look at a further match when alternations tests don't match in length
1 parent 18964be commit 114fa18

10 files changed

+65
-24
lines changed

Gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = function (grunt) {
6363
tasks: {
6464
options: {
6565
filter: "exclude",
66-
tasks: ["availabletasks", "default", "updateDistConfig"],
66+
tasks: ["availabletasks", "default"],
6767
showTasks: ["user"]
6868
}
6969
}

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "inputmask",
3-
"version": "5.0.6-beta.17",
3+
"version": "5.0.6-beta.18",
44
"main": [
55
"./index.js",
66
"./css/inputmask.css"

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "robinherbots/inputmask",
33
"description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.",
4-
"version": "5.0.6-beta.17",
4+
"version": "5.0.6-beta.18",
55
"type": "library",
66
"keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
77
"homepage": "http://robinherbots.github.io/Inputmask",

dist/inputmask.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2020 Robin Herbots
55
* Licensed under the MIT license
6-
* Version: 5.0.6-beta.17
6+
* Version: 5.0.6-beta.18
77
*/
88
!function webpackUniversalModuleDefinition(root, factory) {
99
if ("object" == typeof exports && "object" == typeof module) module.exports = factory(); else if ("function" == typeof define && define.amd) define([], factory); else {
@@ -509,7 +509,7 @@
509509
insertStop = !0, testPos = pos;
510510
}
511511
} else if (match.isAlternator) {
512-
var alternateToken = match, malternateMatches = [], maltMatches, currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = 0 < ndxInitializer.length ? ndxInitializer.shift() : -1;
512+
var alternateToken = match, malternateMatches = [], maltMatches, currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, unMatchedAlternation = !1, altIndex = 0 < ndxInitializer.length ? ndxInitializer.shift() : -1;
513513
if (-1 === altIndex || "string" == typeof altIndex) {
514514
var currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [], amndx;
515515
if ("string" == typeof altIndex) altIndexArr = altIndex.split(","); else for (amndx = 0; amndx < alternateToken.matches.length; amndx++) altIndexArr.push(amndx.toString());
@@ -521,9 +521,11 @@
521521
0 === altIndexArr.length && (delete maskset.excludes[pos], altIndexArr = altIndexArrClone);
522522
}
523523
(!0 === opts.keepStatic || isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic) && (altIndexArr = altIndexArr.slice(0, 1));
524-
for (var unMatchedAlternation = !1, ndx = 0; ndx < altIndexArr.length; ndx++) {
525-
amndx = parseInt(altIndexArr[ndx]), matches = [], ndxInitializer = "string" == typeof altIndex && resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice(),
526-
alternateToken.matches[amndx] && handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse) ? match = !0 : 0 === ndx && (unMatchedAlternation = !0),
524+
for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
525+
amndx = parseInt(altIndexArr[ndx]), matches = [], ndxInitializer = "string" == typeof altIndex && resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice();
526+
var tokenMatch = alternateToken.matches[amndx];
527+
if (tokenMatch && handleMatch(tokenMatch, [ amndx ].concat(loopNdx), quantifierRecurse)) match = !0; else if (0 === ndx && (unMatchedAlternation = !0),
528+
tokenMatch && tokenMatch.matches && tokenMatch.matches.length > alternateToken.matches[0].matches.length) break;
527529
maltMatches = matches.slice(), testPos = currentPos, matches = [];
528530
for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
529531
var altMatch = maltMatches[ndx1], dropMatch = !1;

dist/inputmask.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.inputmask.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2020 Robin Herbots
55
* Licensed under the MIT license
6-
* Version: 5.0.6-beta.17
6+
* Version: 5.0.6-beta.18
77
*/
88
!function webpackUniversalModuleDefinition(root, factory) {
99
if ("object" == typeof exports && "object" == typeof module) module.exports = factory(require("jquery")); else if ("function" == typeof define && define.amd) define([ "jquery" ], factory); else {
@@ -509,7 +509,7 @@
509509
insertStop = !0, testPos = pos;
510510
}
511511
} else if (match.isAlternator) {
512-
var alternateToken = match, malternateMatches = [], maltMatches, currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = 0 < ndxInitializer.length ? ndxInitializer.shift() : -1;
512+
var alternateToken = match, malternateMatches = [], maltMatches, currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, unMatchedAlternation = !1, altIndex = 0 < ndxInitializer.length ? ndxInitializer.shift() : -1;
513513
if (-1 === altIndex || "string" == typeof altIndex) {
514514
var currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [], amndx;
515515
if ("string" == typeof altIndex) altIndexArr = altIndex.split(","); else for (amndx = 0; amndx < alternateToken.matches.length; amndx++) altIndexArr.push(amndx.toString());
@@ -521,9 +521,11 @@
521521
0 === altIndexArr.length && (delete maskset.excludes[pos], altIndexArr = altIndexArrClone);
522522
}
523523
(!0 === opts.keepStatic || isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic) && (altIndexArr = altIndexArr.slice(0, 1));
524-
for (var unMatchedAlternation = !1, ndx = 0; ndx < altIndexArr.length; ndx++) {
525-
amndx = parseInt(altIndexArr[ndx]), matches = [], ndxInitializer = "string" == typeof altIndex && resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice(),
526-
alternateToken.matches[amndx] && handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse) ? match = !0 : 0 === ndx && (unMatchedAlternation = !0),
524+
for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
525+
amndx = parseInt(altIndexArr[ndx]), matches = [], ndxInitializer = "string" == typeof altIndex && resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice();
526+
var tokenMatch = alternateToken.matches[amndx];
527+
if (tokenMatch && handleMatch(tokenMatch, [ amndx ].concat(loopNdx), quantifierRecurse)) match = !0; else if (0 === ndx && (unMatchedAlternation = !0),
528+
tokenMatch && tokenMatch.matches && tokenMatch.matches.length > alternateToken.matches[0].matches.length) break;
527529
maltMatches = matches.slice(), testPos = currentPos, matches = [];
528530
for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
529531
var altMatch = maltMatches[ndx1], dropMatch = !1;

dist/jquery.inputmask.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/validation-tests.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ function getTests(pos, ndxIntlzr, tstPs) {
317317
malternateMatches = [],
318318
maltMatches,
319319
currentMatches = matches.slice(),
320-
loopNdxCnt = loopNdx.length;
320+
loopNdxCnt = loopNdx.length,
321+
unMatchedAlternation = false;
321322
var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
322323
if (altIndex === -1 || typeof altIndex === "string") {
323324
var currentPos = testPos,
@@ -346,16 +347,21 @@ function getTests(pos, ndxIntlzr, tstPs) {
346347
}
347348
}
348349
if (opts.keepStatic === true || (isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic)) altIndexArr = altIndexArr.slice(0, 1);
349-
var unMatchedAlternation = false;
350350
for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
351351
amndx = parseInt(altIndexArr[ndx]);
352352
matches = [];
353353
//set the correct ndxInitializer
354354
ndxInitializer = typeof altIndex === "string" ? resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice() : ndxInitializerClone.slice();
355-
if (alternateToken.matches[amndx] && handleMatch(alternateToken.matches[amndx], [amndx].concat(loopNdx), quantifierRecurse)) {
355+
var tokenMatch = alternateToken.matches[amndx];
356+
if (tokenMatch && handleMatch(tokenMatch, [amndx].concat(loopNdx), quantifierRecurse)) {
356357
match = true;
357-
} else if (ndx === 0) {
358-
unMatchedAlternation = true;
358+
} else {
359+
if(ndx === 0) {
360+
unMatchedAlternation = true;
361+
}
362+
if (tokenMatch && tokenMatch.matches && tokenMatch.matches.length > alternateToken.matches[0].matches.length) {
363+
break;
364+
}
359365
}
360366

361367
maltMatches = matches.slice();

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "inputmask",
3-
"version": "5.0.6-beta.17",
3+
"version": "5.0.6-beta.18",
44
"description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.",
55
"main": "dist/inputmask.js",
66
"files": [

qunit/tests_alternations.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,35 @@ export default function (qunit, Inputmask) {
442442
$("#testmask").Type("26");
443443
assert.equal(testmask.inputmask._valueGet(), "2", "Result " + testmask.inputmask._valueGet());
444444
});
445-
};
445+
446+
qunit.test("+(1|\\90|221) (999) 999 99-99 - type 1 - tcagkansokmen", function (assert) {
447+
var $fixture = $("#qunit-fixture");
448+
$fixture.append("<input type=\"text\" id=\"testmask\" />");
449+
var testmask = document.getElementById("testmask");
450+
451+
Inputmask("+(1|\\90|221) (999) 999 99-99").mask(testmask);
452+
testmask.focus();
453+
$("#testmask").Type("1");
454+
assert.equal(testmask.inputmask._valueGet(), "+1 (___) ___ __-__", "Result " + testmask.inputmask._valueGet());
455+
});
456+
qunit.test("+(1|\\90|221) (999) 999 99-99 - type 9 - tcagkansokmen", function (assert) {
457+
var $fixture = $("#qunit-fixture");
458+
$fixture.append("<input type=\"text\" id=\"testmask\" />");
459+
var testmask = document.getElementById("testmask");
460+
461+
Inputmask("+(1|\\90|221) (999) 999 99-99").mask(testmask);
462+
testmask.focus();
463+
$("#testmask").Type("9");
464+
assert.equal(testmask.inputmask._valueGet(), "+90 (___) ___ __-__", "Result " + testmask.inputmask._valueGet());
465+
});
466+
qunit.test("+(1|\\90|221) (999) 999 99-99 - type 2 - tcagkansokmen", function (assert) {
467+
var $fixture = $("#qunit-fixture");
468+
$fixture.append("<input type=\"text\" id=\"testmask\" />");
469+
var testmask = document.getElementById("testmask");
470+
471+
Inputmask("+(1|\\90|221) (999) 999 99-99").mask(testmask);
472+
testmask.focus();
473+
$("#testmask").Type("2");
474+
assert.equal(testmask.inputmask._valueGet(), "+221 (___) ___ __-__", "Result " + testmask.inputmask._valueGet());
475+
});
476+
}

0 commit comments

Comments
 (0)