Browse Source

Update IP extension to support greedy option #2748

Robin Herbots 2 years ago
parent
commit
f93ee5b5ae

+ 2 - 0
Changelog.md

@@ -6,10 +6,12 @@
 - Add exports field in package.json #2690
 
 ### Updates
+- Update IP extension to support greedy option. #2748
 - Properly handle insertMode false in alternation logic.
 - Enhance resolving of the ndxInitializer to determine the alternating tests.
 
 ### Fixed
+- [Question] How to custom placeholder in "ip" alias? #2749
 - Timezone mask #2730
 - Unicode categories such as \p{P} or \p{S} does not work in regexp property #2741
 - When user press Ctrl+Alt / Alt+Ctrl key in the field, Can input characters with restricted formatting #2736

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.9-beta.33",
+  "version": "5.0.9-beta.35",
   "main": [
 	  "./index.js",
     "./css/inputmask.css"

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
   "name": "robinherbots/inputmask",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
-  "version": "5.0.9-beta.33",
+  "version": "5.0.9-beta.35",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/Inputmask",

+ 60 - 33
dist/inputmask.js

@@ -3,7 +3,7 @@
  * https://github.com/RobinHerbots/Inputmask
  * Copyright (c) 2010 - 2023 Robin Herbots
  * Licensed under the MIT license
- * Version: 5.0.9-beta.33
+ * Version: 5.0.9-beta.35
  */
 !function(e, t) {
     if ("object" == typeof exports && "object" == typeof module) module.exports = t(); else if ("function" == typeof define && define.amd) define([], t); else {
@@ -1399,6 +1399,27 @@
                 var i, a = (i = n(2394)) && i.__esModule ? i : {
                     default: i
                 }, r = n(8711), o = n(4713);
+                function l(e) {
+                    return function(e) {
+                        if (Array.isArray(e)) return s(e);
+                    }(e) || function(e) {
+                        if ("undefined" != typeof Symbol && null != e[Symbol.iterator] || null != e["@@iterator"]) return Array.from(e);
+                    }(e) || function(e, t) {
+                        if (!e) return;
+                        if ("string" == typeof e) return s(e, t);
+                        var n = Object.prototype.toString.call(e).slice(8, -1);
+                        "Object" === n && e.constructor && (n = e.constructor.name);
+                        if ("Map" === n || "Set" === n) return Array.from(e);
+                        if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return s(e, t);
+                    }(e) || function() {
+                        throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+                    }();
+                }
+                function s(e, t) {
+                    (null == t || t > e.length) && (t = e.length);
+                    for (var n = 0, i = new Array(t); n < t; n++) i[n] = e[n];
+                    return i;
+                }
                 a.default.extendDefinitions({
                     A: {
                         validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
@@ -1413,10 +1434,14 @@
                         casing: "upper"
                     }
                 });
-                var l = new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]");
-                function s(e, t, n, i, a) {
+                var c = new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]");
+                function u(e, t, n, i, a) {
                     return n - 1 > -1 && "." !== t.buffer[n - 1] ? (e = t.buffer[n - 1] + e, e = n - 2 > -1 && "." !== t.buffer[n - 2] ? t.buffer[n - 2] + e : "0" + e) : e = "00" + e, 
-                    l.test(e);
+                    a.greedy && parseInt(e) > 255 && c.test("00" + e.charAt(2)) ? {
+                        refreshFromBuffer: !0,
+                        buffer: [].concat(l(t.buffer.slice(0, n)), [ ".", e.charAt(2) ]),
+                        caret: n + 2
+                    } : c.test(e);
                 }
                 a.default.extendAliases({
                     cssunit: {
@@ -1432,16 +1457,16 @@
                         mask: "i{1,3}.j{1,3}.k{1,3}.l{1,3}",
                         definitions: {
                             i: {
-                                validator: s
+                                validator: u
                             },
                             j: {
-                                validator: s
+                                validator: u
                             },
                             k: {
-                                validator: s
+                                validator: u
                             },
                             l: {
-                                validator: s
+                                validator: u
                             }
                         },
                         onUnMask: function(e, t, n) {
@@ -3577,7 +3602,7 @@
                 }
                 function v(e, t, n, a) {
                     var o = this, l = this.maskset, s = this.opts, c = this.dependencyLib;
-                    function u(e, t, n) {
+                    function d(e, t, n) {
                         var i = t[e];
                         if (void 0 !== i && !0 === i.match.static && !0 !== i.match.optionality && (void 0 === t[0] || void 0 === t[0].alternation)) {
                             var a = n.begin <= e - 1 ? t[e - 1] && !0 === t[e - 1].match.static && t[e - 1] : t[e - 1], r = n.end > e + 1 ? t[e + 1] && !0 === t[e + 1].match.static && t[e + 1] : t[e + 1];
@@ -3585,38 +3610,40 @@
                         }
                         return !1;
                     }
-                    var d = 0, h = void 0 !== e.begin ? e.begin : e, v = void 0 !== e.end ? e.end : e, m = !0;
-                    if (e.begin > e.end && (h = e.end, v = e.begin), a = void 0 !== a ? a : h, void 0 === n && (h !== v || s.insertMode && void 0 !== l.validPositions[a] || void 0 === t || t.match.optionalQuantifier || t.match.optionality)) {
-                        var g, y = c.extend(!0, [], l.validPositions), k = r.getLastValidPosition.call(o, void 0, !0);
-                        for (l.p = h, g = k; g >= h; g--) l.validPositions.splice(g, 1), void 0 === t && delete l.tests[g + 1];
-                        var b, x, P = a, w = P;
-                        for (t && (l.validPositions[a] = c.extend(!0, {}, t), w++, P++), null == y[v] && l.jitOffset[v] && (v += l.jitOffset[v] + 1), 
-                        g = t ? v : v - 1; g <= k; g++) {
-                            if (void 0 !== (b = y[g]) && !0 !== b.generatedInput && (g >= v || g >= h && u(g, y, {
-                                begin: h,
-                                end: v
+                    var h = 0, v = void 0 !== e.begin ? e.begin : e, m = void 0 !== e.end ? e.end : e, g = !0;
+                    if (e.begin > e.end && (v = e.end, m = e.begin), a = void 0 !== a ? a : v, void 0 === n && (v !== m || s.insertMode && void 0 !== l.validPositions[a] || void 0 === t || t.match.optionalQuantifier || t.match.optionality)) {
+                        var y, k = c.extend(!0, [], l.validPositions), b = r.getLastValidPosition.call(o, void 0, !0);
+                        l.p = v;
+                        var x = u.call(o, e) ? v : a;
+                        for (y = b; y >= x; y--) l.validPositions.splice(y, 1), void 0 === t && delete l.tests[y + 1];
+                        var P, w, S = a, O = S;
+                        for (t && (l.validPositions[a] = c.extend(!0, {}, t), O++, S++), null == k[m] && l.jitOffset[m] && (m += l.jitOffset[m] + 1), 
+                        y = t ? m : m - 1; y <= b; y++) {
+                            if (void 0 !== (P = k[y]) && !0 !== P.generatedInput && (y >= m || y >= v && d(y, k, {
+                                begin: v,
+                                end: m
                             }))) {
-                                for (;"" !== i.getTest.call(o, w).match.def; ) {
-                                    if (!1 !== (x = p.call(o, w, b, s)) || "+" === b.match.def) {
-                                        "+" === b.match.def && r.getBuffer.call(o, !0);
-                                        var S = f.call(o, w, b.input, "+" !== b.match.def, !0);
-                                        if (m = !1 !== S, P = (S.pos || w) + 1, !m && x) break;
-                                    } else m = !1;
-                                    if (m) {
-                                        void 0 === t && b.match.static && g === e.begin && d++;
+                                for (;"" !== i.getTest.call(o, O).match.def; ) {
+                                    if (!1 !== (w = p.call(o, O, P, s)) || "+" === P.match.def) {
+                                        "+" === P.match.def && r.getBuffer.call(o, !0);
+                                        var _ = f.call(o, O, P.input, "+" !== P.match.def, !0);
+                                        if (g = !1 !== _, S = (_.pos || O) + 1, !g && w) break;
+                                    } else g = !1;
+                                    if (g) {
+                                        void 0 === t && P.match.static && y === e.begin && h++;
                                         break;
                                     }
-                                    if (!m && r.getBuffer.call(o), w > l.maskLength) break;
-                                    w++;
+                                    if (!g && r.getBuffer.call(o), O > l.maskLength) break;
+                                    O++;
                                 }
-                                "" == i.getTest.call(o, w).match.def && (m = !1), w = P;
+                                "" == i.getTest.call(o, O).match.def && (g = !1), O = S;
                             }
-                            if (!m) break;
+                            if (!g) break;
                         }
-                        if (!m) return l.validPositions = c.extend(!0, [], y), r.resetMaskSet.call(o, !0), 
+                        if (!g) return l.validPositions = c.extend(!0, [], k), r.resetMaskSet.call(o, !0), 
                         !1;
                     } else t && i.getTest.call(o, a).match.cd === t.match.cd && (l.validPositions[a] = c.extend(!0, {}, t));
-                    return r.resetMaskSet.call(o, !0), d;
+                    return r.resetMaskSet.call(o, !0), h;
                 }
             }
         }, t = {};

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


+ 93 - 66
dist/jquery.inputmask.js

@@ -3,7 +3,7 @@
  * https://github.com/RobinHerbots/Inputmask
  * Copyright (c) 2010 - 2023 Robin Herbots
  * Licensed under the MIT license
- * Version: 5.0.9-beta.33
+ * Version: 5.0.9-beta.35
  */
 !function(e, t) {
     if ("object" == typeof exports && "object" == typeof module) module.exports = t(require("jquery")); else if ("function" == typeof define && define.amd) define([ "jquery" ], t); else {
@@ -1230,6 +1230,27 @@
                 var n, a = (n = i(2394)) && n.__esModule ? n : {
                     default: n
                 }, r = i(8711), o = i(4713);
+                function s(e) {
+                    return function(e) {
+                        if (Array.isArray(e)) return l(e);
+                    }(e) || function(e) {
+                        if ("undefined" != typeof Symbol && null != e[Symbol.iterator] || null != e["@@iterator"]) return Array.from(e);
+                    }(e) || function(e, t) {
+                        if (!e) return;
+                        if ("string" == typeof e) return l(e, t);
+                        var i = Object.prototype.toString.call(e).slice(8, -1);
+                        "Object" === i && e.constructor && (i = e.constructor.name);
+                        if ("Map" === i || "Set" === i) return Array.from(e);
+                        if ("Arguments" === i || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)) return l(e, t);
+                    }(e) || function() {
+                        throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+                    }();
+                }
+                function l(e, t) {
+                    (null == t || t > e.length) && (t = e.length);
+                    for (var i = 0, n = new Array(t); i < t; i++) n[i] = e[i];
+                    return n;
+                }
                 a.default.extendDefinitions({
                     A: {
                         validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
@@ -1244,10 +1265,14 @@
                         casing: "upper"
                     }
                 });
-                var s = new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]");
-                function l(e, t, i, n, a) {
+                var c = new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]");
+                function u(e, t, i, n, a) {
                     return i - 1 > -1 && "." !== t.buffer[i - 1] ? (e = t.buffer[i - 1] + e, e = i - 2 > -1 && "." !== t.buffer[i - 2] ? t.buffer[i - 2] + e : "0" + e) : e = "00" + e, 
-                    s.test(e);
+                    a.greedy && parseInt(e) > 255 && c.test("00" + e.charAt(2)) ? {
+                        refreshFromBuffer: !0,
+                        buffer: [].concat(s(t.buffer.slice(0, i)), [ ".", e.charAt(2) ]),
+                        caret: i + 2
+                    } : c.test(e);
                 }
                 a.default.extendAliases({
                     cssunit: {
@@ -1263,16 +1288,16 @@
                         mask: "i{1,3}.j{1,3}.k{1,3}.l{1,3}",
                         definitions: {
                             i: {
-                                validator: l
+                                validator: u
                             },
                             j: {
-                                validator: l
+                                validator: u
                             },
                             k: {
-                                validator: l
+                                validator: u
                             },
                             l: {
-                                validator: l
+                                validator: u
                             }
                         },
                         onUnMask: function(e, t, i) {
@@ -2510,14 +2535,14 @@
 
                           case i.alternatormarker:
                             if (v.length > 0) {
-                                var D = (l = v[v.length - 1]).matches[l.matches.length - 1];
-                                u = l.openGroup && (void 0 === D.matches || !1 === D.isGroup && !1 === D.isAlternator) ? v.pop() : P(l.matches);
+                                var A = (l = v[v.length - 1]).matches[l.matches.length - 1];
+                                u = l.openGroup && (void 0 === A.matches || !1 === A.isGroup && !1 === A.isAlternator) ? v.pop() : P(l.matches);
                             } else u = P(h.matches);
                             if (u.isAlternator) v.push(u); else if (u.alternatorGroup ? (c = v.pop(), u.alternatorGroup = !1) : c = new a.default(!1, !1, !1, !0), 
                             c.matches.push(u), v.push(c), u.openGroup) {
                                 u.openGroup = !1;
-                                var A = new a.default(!0);
-                                A.alternatorGroup = !0, v.push(A);
+                                var D = new a.default(!0);
+                                D.alternatorGroup = !0, v.push(D);
                             }
                             break;
 
@@ -3120,11 +3145,11 @@
                                         var _, E = h, j = i.slice(), T = [];
                                         if ("string" == typeof M) T = M.split(","); else for (_ = 0; _ < y.matches.length; _++) T.push(_.toString());
                                         if (void 0 !== l.excludes[e]) {
-                                            for (var D = T.slice(), A = 0, L = l.excludes[e].length; A < L; A++) {
-                                                var B = l.excludes[e][A].toString().split(":");
+                                            for (var A = T.slice(), D = 0, L = l.excludes[e].length; D < L; D++) {
+                                                var B = l.excludes[e][D].toString().split(":");
                                                 s.length == B[1] && T.splice(T.indexOf(B[0]), 1);
                                             }
-                                            0 === T.length && (delete l.excludes[e], T = D);
+                                            0 === T.length && (delete l.excludes[e], T = A);
                                         }
                                         (!0 === u.keepStatic || isFinite(parseInt(u.keepStatic)) && E >= u.keepStatic) && (T = T.slice(0, 1));
                                         for (var C = 0; C < T.length; C++) {
@@ -3132,31 +3157,31 @@
                                             var R = y.matches[_];
                                             if (R && c(R, [ _ ].concat(s), d)) r = !0; else if (0 === C && (O = !0), R && R.matches && R.matches.length > y.matches[0].matches.length) break;
                                             n = m.slice(), h = E, m = [];
-                                            for (var F = 0; F < n.length; F++) {
-                                                var I = n[F], N = !1;
-                                                I.match.jit = I.match.jit || O, I.alternation = I.alternation || S, P(I);
+                                            for (var I = 0; I < n.length; I++) {
+                                                var F = n[I], N = !1;
+                                                F.match.jit = F.match.jit || O, F.alternation = F.alternation || S, P(F);
                                                 for (var V = 0; V < k.length; V++) {
                                                     var G = k[V];
-                                                    if ("string" != typeof M || void 0 !== I.alternation && T.includes(I.locator[I.alternation].toString())) {
-                                                        if (I.match.nativeDef === G.match.nativeDef) {
-                                                            N = !0, P(G, I);
+                                                    if ("string" != typeof M || void 0 !== F.alternation && T.includes(F.locator[F.alternation].toString())) {
+                                                        if (F.match.nativeDef === G.match.nativeDef) {
+                                                            N = !0, P(G, F);
                                                             break;
                                                         }
-                                                        if (f(I, G, u)) {
-                                                            P(I, G) && (N = !0, k.splice(k.indexOf(G), 0, I));
+                                                        if (f(F, G, u)) {
+                                                            P(F, G) && (N = !0, k.splice(k.indexOf(G), 0, F));
                                                             break;
                                                         }
-                                                        if (f(G, I, u)) {
-                                                            P(G, I);
+                                                        if (f(G, F, u)) {
+                                                            P(G, F);
                                                             break;
                                                         }
-                                                        if (v = G, !0 === (a = I).match.static && !0 !== v.match.static && v.match.fn.test(a.match.def, l, e, !1, u, !1)) {
-                                                            w(I, G) || void 0 !== p.inputmask.userOptions.keepStatic ? P(I, G) && (N = !0, k.splice(k.indexOf(G), 0, I)) : u.keepStatic = !0;
+                                                        if (v = G, !0 === (a = F).match.static && !0 !== v.match.static && v.match.fn.test(a.match.def, l, e, !1, u, !1)) {
+                                                            w(F, G) || void 0 !== p.inputmask.userOptions.keepStatic ? P(F, G) && (N = !0, k.splice(k.indexOf(G), 0, F)) : u.keepStatic = !0;
                                                             break;
                                                         }
                                                     }
                                                 }
-                                                N || k.push(I);
+                                                N || k.push(F);
                                             }
                                         }
                                         m = b.concat(k), h = e, g = m.length > 0, r = k.length > 0, i = j.slice();
@@ -3271,13 +3296,13 @@
                     if (void 0 !== u) {
                         m = parseInt(c), S.excludes[m] = S.excludes[m] || [], !0 !== e && S.excludes[m].push((0, 
                         n.getDecisionTaker)(d) + ":" + d.alternation);
-                        var T = [], D = -1;
-                        for (h = m; m < r.getLastValidPosition.call(x, void 0, !0) + 1; h++) -1 === D && e <= h && void 0 !== t && (T.push(t), 
-                        D = T.length - 1), (v = S.validPositions[m]) && !0 !== v.generatedInput && (void 0 === l || h < k || h >= b) && T.push(v.input), 
+                        var T = [], A = -1;
+                        for (h = m; m < r.getLastValidPosition.call(x, void 0, !0) + 1; h++) -1 === A && e <= h && void 0 !== t && (T.push(t), 
+                        A = T.length - 1), (v = S.validPositions[m]) && !0 !== v.generatedInput && (void 0 === l || h < k || h >= b) && T.push(v.input), 
                         S.validPositions.splice(m, 1);
-                        for (-1 === D && void 0 !== t && (T.push(t), D = T.length - 1); void 0 !== S.excludes[m] && S.excludes[m].length < 10; ) {
+                        for (-1 === A && void 0 !== t && (T.push(t), A = T.length - 1); void 0 !== S.excludes[m] && S.excludes[m].length < 10; ) {
                             for (S.tests = {}, r.resetMaskSet.call(x, !0), _ = !0, h = 0; h < T.length && (g = _.caret || 0 == w.insertMode && null != g ? r.seekNext.call(x, g) : r.getLastValidPosition.call(x, void 0, !0) + 1, 
-                            y = T[h], _ = f.call(x, g, y, !1, a, !0)); h++) h === D && (E = _), 1 == e && _ && (E = {
+                            y = T[h], _ = f.call(x, g, y, !1, a, !0)); h++) h === A && (E = _), 1 == e && _ && (E = {
                                 caretPos: h
                             });
                             if (_) break;
@@ -3287,12 +3312,12 @@
                                 break;
                             }
                             if (null != d.alternation) {
-                                var A = (0, n.getDecisionTaker)(d);
-                                if (-1 !== S.excludes[m].indexOf(A + ":" + d.alternation)) {
+                                var D = (0, n.getDecisionTaker)(d);
+                                if (-1 !== S.excludes[m].indexOf(D + ":" + d.alternation)) {
                                     E = s.call(x, e, t, i, a, m - 1, l);
                                     break;
                                 }
-                                for (S.excludes[m].push(A + ":" + d.alternation), h = m; h < r.getLastValidPosition.call(x, void 0, !0) + 1; h++) S.validPositions.splice(m);
+                                for (S.excludes[m].push(D + ":" + d.alternation), h = m; h < r.getLastValidPosition.call(x, void 0, !0) + 1; h++) S.validPositions.splice(m);
                             } else delete S.excludes[m];
                         }
                     }
@@ -3415,15 +3440,15 @@
                         });
                     }
                     if ("function" == typeof k.postValidation && !0 !== a && !0 !== p) {
-                        var D = k.postValidation.call(g, r.getBuffer.call(g, !0), void 0 !== e.begin ? g.isRTL ? e.end : e.begin : e, t, S, k, b, i, m);
-                        void 0 !== D && (S = !0 === D ? S : D);
+                        var A = k.postValidation.call(g, r.getBuffer.call(g, !0), void 0 !== e.begin ? g.isRTL ? e.end : e.begin : e, t, S, k, b, i, m);
+                        void 0 !== A && (S = !0 === A ? S : A);
                     }
                     S && void 0 === S.pos && (S.pos = x), !1 === S || !0 === p ? (r.resetMaskSet.call(g, !0), 
                     b.validPositions = y.extend(!0, [], O)) : h.call(g, void 0, x, !0);
-                    var A = P(S);
+                    var D = P(S);
                     void 0 !== g.maxLength && (r.getBuffer.call(g).length > g.maxLength && !a && (r.resetMaskSet.call(g, !0), 
-                    b.validPositions = y.extend(!0, [], O), A = !1));
-                    return A;
+                    b.validPositions = y.extend(!0, [], O), D = !1));
+                    return D;
                 }
                 function p(e, t, i) {
                     for (var a = this.maskset, r = !1, o = n.getTests.call(this, e), s = 0; s < o.length; s++) {
@@ -3476,7 +3501,7 @@
                 }
                 function v(e, t, i, a) {
                     var o = this, s = this.maskset, l = this.opts, c = this.dependencyLib;
-                    function u(e, t, i) {
+                    function d(e, t, i) {
                         var n = t[e];
                         if (void 0 !== n && !0 === n.match.static && !0 !== n.match.optionality && (void 0 === t[0] || void 0 === t[0].alternation)) {
                             var a = i.begin <= e - 1 ? t[e - 1] && !0 === t[e - 1].match.static && t[e - 1] : t[e - 1], r = i.end > e + 1 ? t[e + 1] && !0 === t[e + 1].match.static && t[e + 1] : t[e + 1];
@@ -3484,38 +3509,40 @@
                         }
                         return !1;
                     }
-                    var d = 0, h = void 0 !== e.begin ? e.begin : e, v = void 0 !== e.end ? e.end : e, m = !0;
-                    if (e.begin > e.end && (h = e.end, v = e.begin), a = void 0 !== a ? a : h, void 0 === i && (h !== v || l.insertMode && void 0 !== s.validPositions[a] || void 0 === t || t.match.optionalQuantifier || t.match.optionality)) {
-                        var g, y = c.extend(!0, [], s.validPositions), k = r.getLastValidPosition.call(o, void 0, !0);
-                        for (s.p = h, g = k; g >= h; g--) s.validPositions.splice(g, 1), void 0 === t && delete s.tests[g + 1];
-                        var b, x, P = a, w = P;
-                        for (t && (s.validPositions[a] = c.extend(!0, {}, t), w++, P++), null == y[v] && s.jitOffset[v] && (v += s.jitOffset[v] + 1), 
-                        g = t ? v : v - 1; g <= k; g++) {
-                            if (void 0 !== (b = y[g]) && !0 !== b.generatedInput && (g >= v || g >= h && u(g, y, {
-                                begin: h,
-                                end: v
+                    var h = 0, v = void 0 !== e.begin ? e.begin : e, m = void 0 !== e.end ? e.end : e, g = !0;
+                    if (e.begin > e.end && (v = e.end, m = e.begin), a = void 0 !== a ? a : v, void 0 === i && (v !== m || l.insertMode && void 0 !== s.validPositions[a] || void 0 === t || t.match.optionalQuantifier || t.match.optionality)) {
+                        var y, k = c.extend(!0, [], s.validPositions), b = r.getLastValidPosition.call(o, void 0, !0);
+                        s.p = v;
+                        var x = u.call(o, e) ? v : a;
+                        for (y = b; y >= x; y--) s.validPositions.splice(y, 1), void 0 === t && delete s.tests[y + 1];
+                        var P, w, S = a, O = S;
+                        for (t && (s.validPositions[a] = c.extend(!0, {}, t), O++, S++), null == k[m] && s.jitOffset[m] && (m += s.jitOffset[m] + 1), 
+                        y = t ? m : m - 1; y <= b; y++) {
+                            if (void 0 !== (P = k[y]) && !0 !== P.generatedInput && (y >= m || y >= v && d(y, k, {
+                                begin: v,
+                                end: m
                             }))) {
-                                for (;"" !== n.getTest.call(o, w).match.def; ) {
-                                    if (!1 !== (x = p.call(o, w, b, l)) || "+" === b.match.def) {
-                                        "+" === b.match.def && r.getBuffer.call(o, !0);
-                                        var S = f.call(o, w, b.input, "+" !== b.match.def, !0);
-                                        if (m = !1 !== S, P = (S.pos || w) + 1, !m && x) break;
-                                    } else m = !1;
-                                    if (m) {
-                                        void 0 === t && b.match.static && g === e.begin && d++;
+                                for (;"" !== n.getTest.call(o, O).match.def; ) {
+                                    if (!1 !== (w = p.call(o, O, P, l)) || "+" === P.match.def) {
+                                        "+" === P.match.def && r.getBuffer.call(o, !0);
+                                        var M = f.call(o, O, P.input, "+" !== P.match.def, !0);
+                                        if (g = !1 !== M, S = (M.pos || O) + 1, !g && w) break;
+                                    } else g = !1;
+                                    if (g) {
+                                        void 0 === t && P.match.static && y === e.begin && h++;
                                         break;
                                     }
-                                    if (!m && r.getBuffer.call(o), w > s.maskLength) break;
-                                    w++;
+                                    if (!g && r.getBuffer.call(o), O > s.maskLength) break;
+                                    O++;
                                 }
-                                "" == n.getTest.call(o, w).match.def && (m = !1), w = P;
+                                "" == n.getTest.call(o, O).match.def && (g = !1), O = S;
                             }
-                            if (!m) break;
+                            if (!g) break;
                         }
-                        if (!m) return s.validPositions = c.extend(!0, [], y), r.resetMaskSet.call(o, !0), 
+                        if (!g) return s.validPositions = c.extend(!0, [], k), r.resetMaskSet.call(o, !0), 
                         !1;
                     } else t && n.getTest.call(o, a).match.cd === t.match.cd && (s.validPositions[a] = c.extend(!0, {}, t));
-                    return r.resetMaskSet.call(o, !0), d;
+                    return r.resetMaskSet.call(o, !0), h;
                 }
             },
             7957: function(t) {

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


+ 5 - 1
inputmask-pages/src/Components/Demo/Demo.js

@@ -34,7 +34,11 @@ export const Demo = () => {
         maskOptions={{ alias: "decimal", groupSeparator: "," }}
         comment="Group separator: , RadixPoint: ."
       />
-      <DemoMask label="IP address:" maskOptions={{ alias: "ip" }} />
+      <DemoMask
+        label="IP address:"
+        maskOptions={{ alias: "ip", greedy: true }}
+        comment="greedy: true"
+      />
       <DemoMask label="Email address:" maskOptions={{ alias: "email" }} />
     </div>
   );

+ 2 - 0
inputmask-pages/src/assets/Changelog.md

@@ -6,10 +6,12 @@
 - Add exports field in package.json #2690
 
 ### Updates
+- Update IP extension to support greedy option. #2748
 - Properly handle insertMode false in alternation logic.
 - Enhance resolving of the ndxInitializer to determine the alternating tests.
 
 ### Fixed
+- [Question] How to custom placeholder in "ip" alias? #2749
 - Timezone mask #2730
 - Unicode categories such as \p{P} or \p{S} does not work in regexp property #2741
 - When user press Ctrl+Alt / Alt+Ctrl key in the field, Can input characters with restricted formatting #2736

+ 91 - 111
lib/extensions/inputmask.extensions.js

@@ -9,124 +9,104 @@ import {getLastValidPosition} from "../positioning";
 import {getMaskTemplate} from "../validation-tests";
 //extra definitions
 Inputmask.extendDefinitions({
-    "A": {
-        validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
-        casing: "upper" //auto uppercasing
-    },
-    "&": { //alfanumeric uppercasing
-        validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
-        casing: "upper"
-    },
-    "#": { //hexadecimal
-        validator: "[0-9A-Fa-f]",
-        casing: "upper"
-    }
+	"A": {
+		validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]", casing: "upper" //auto uppercasing
+	}, "&": { //alfanumeric uppercasing
+		validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]", casing: "upper"
+	}, "#": { //hexadecimal
+		validator: "[0-9A-Fa-f]", casing: "upper"
+	}
 });
 
 var ipValidatorRegex = new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]");
 
 function ipValidator(chrs, maskset, pos, strict, opts) {
-    if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
-        chrs = maskset.buffer[pos - 1] + chrs;
-        if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
-            chrs = maskset.buffer[pos - 2] + chrs;
-        } else chrs = "0" + chrs;
-    } else chrs = "00" + chrs;
-    return ipValidatorRegex.test(chrs);
+	if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
+		chrs = maskset.buffer[pos - 1] + chrs;
+		if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
+			chrs = maskset.buffer[pos - 2] + chrs;
+		} else chrs = "0" + chrs;
+	} else chrs = "00" + chrs;
+	if (opts.greedy && parseInt(chrs) > 255 && ipValidatorRegex.test("00" + chrs.charAt(2))) {
+		return {
+			refreshFromBuffer: true,
+			buffer: [...maskset.buffer.slice(0, pos), ".", chrs.charAt(2)],
+			caret: pos + 2
+		};
+	}
+	return ipValidatorRegex.test(chrs);
 }
 
 
 Inputmask.extendAliases({
-    "cssunit": {
-        regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)"
-    },
-    "url": { //needs update => https://en.wikipedia.org/wiki/URL
-        regex: "(https?|ftp)://.*",
-        autoUnmask: false,
-        keepStatic: false,
-        tabThrough: true
-    },
-    "ip": { //ip-address mask
-        mask: "i{1,3}.j{1,3}.k{1,3}.l{1,3}",
-        definitions: {
-            "i": {
-                validator: ipValidator
-            },
-            "j": {
-                validator: ipValidator
-            },
-            "k": {
-                validator: ipValidator
-            },
-            "l": {
-                validator: ipValidator
-            }
-        },
-        onUnMask: function (maskedValue, unmaskedValue, opts) {
-            return maskedValue;
-        },
-        inputmode: "decimal",
-        substitutes: {",": "."}
-    },
-    "email": {
-        //https://en.wikipedia.org/wiki/Domain_name#Domain_name_space
-        //https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
-        //should be extended with the toplevel domains at the end
-        mask: function ({separator, quantifier}) {
-            var emailMask = "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]";
-            var mask = emailMask;
-            if (separator) {
-                for (let i = 0; i < quantifier; i++) {
-                    mask += `[${separator}${emailMask}]`;
-                }
-            }
-            return mask;
-        },
-        greedy: false,
-        casing: "lower",
-        separator: null,
-        quantifier: 5,
-        skipOptionalPartCharacter: "",
-        onBeforePaste: function (pastedValue, opts) {
-            pastedValue = pastedValue.toLowerCase();
-            return pastedValue.replace("mailto:", "");
-        },
-        definitions: {
-            "*": {
-                validator: "[0-9\uFF11-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5!#$%&'*+/=?^_`{|}~-]"
-            },
-            "-": {
-                validator: "[0-9A-Za-z-]"
-            }
-        },
-        onUnMask: function (maskedValue, unmaskedValue, opts) {
-            return maskedValue;
-        },
-        inputmode: "email"
-    },
-    "mac": {
-        mask: "##:##:##:##:##:##"
-    },
-    //https://en.wikipedia.org/wiki/Vehicle_identification_number
-    // see issue #1199
-    "vin": {
-        mask: "V{13}9{4}",
-        definitions: {
-            "V": {
-                validator: "[A-HJ-NPR-Za-hj-npr-z\\d]",
-                casing: "upper"
-            }
-        },
-        clearIncomplete: true,
-        autoUnmask: true
-    },
-    //http://rion.io/2013/09/10/validating-social-security-numbers-through-regular-expressions-2/
-    //https://en.wikipedia.org/wiki/Social_Security_number
-    "ssn": {
-        mask: "999-99-9999",
-        postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) {
-            var bffr = getMaskTemplate.call(this, true, getLastValidPosition.call(this), true, true);
-            return /^(?!219-09-9999|078-05-1120)(?!666|000|9.{2}).{3}-(?!00).{2}-(?!0{4}).{4}$/.test(bffr.join(""));
-        }
-    },
+	"cssunit": {
+		regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)"
+	}, "url": { //needs update => https://en.wikipedia.org/wiki/URL
+		regex: "(https?|ftp)://.*", autoUnmask: false, keepStatic: false, tabThrough: true
+	}, "ip": { //ip-address mask
+		mask: "i{1,3}.j{1,3}.k{1,3}.l{1,3}", definitions: {
+			"i": {
+				validator: ipValidator
+			}, "j": {
+				validator: ipValidator
+			}, "k": {
+				validator: ipValidator
+			}, "l": {
+				validator: ipValidator
+			}
+		}, onUnMask: function (maskedValue, unmaskedValue, opts) {
+			return maskedValue;
+		}, inputmode: "decimal", substitutes: {",": "."}
+	}, "email": {
+		//https://en.wikipedia.org/wiki/Domain_name#Domain_name_space
+		//https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
+		//should be extended with the toplevel domains at the end
+		mask: function ({separator, quantifier}) {
+			var emailMask = "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]";
+			var mask = emailMask;
+			if (separator) {
+				for (let i = 0; i < quantifier; i++) {
+					mask += `[${separator}${emailMask}]`;
+				}
+			}
+			return mask;
+		},
+		greedy: false,
+		casing: "lower",
+		separator: null,
+		quantifier: 5,
+		skipOptionalPartCharacter: "",
+		onBeforePaste: function (pastedValue, opts) {
+			pastedValue = pastedValue.toLowerCase();
+			return pastedValue.replace("mailto:", "");
+		},
+		definitions: {
+			"*": {
+				validator: "[0-9\uFF11-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5!#$%&'*+/=?^_`{|}~-]"
+			}, "-": {
+				validator: "[0-9A-Za-z-]"
+			}
+		},
+		onUnMask: function (maskedValue, unmaskedValue, opts) {
+			return maskedValue;
+		},
+		inputmode: "email"
+	}, "mac": {
+		mask: "##:##:##:##:##:##"
+	}, //https://en.wikipedia.org/wiki/Vehicle_identification_number
+	// see issue #1199
+	"vin": {
+		mask: "V{13}9{4}", definitions: {
+			"V": {
+				validator: "[A-HJ-NPR-Za-hj-npr-z\\d]", casing: "upper"
+			}
+		}, clearIncomplete: true, autoUnmask: true
+	}, //http://rion.io/2013/09/10/validating-social-security-numbers-through-regular-expressions-2/
+	//https://en.wikipedia.org/wiki/Social_Security_number
+	"ssn": {
+		mask: "999-99-9999", postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) {
+			var bffr = getMaskTemplate.call(this, true, getLastValidPosition.call(this), true, true);
+			return /^(?!219-09-9999|078-05-1120)(?!666|000|9.{2}).{3}-(?!00).{2}-(?!0{4}).{4}$/.test(bffr.join(""));
+		}
+	},
 });

+ 3 - 2
lib/validation.js

@@ -340,7 +340,7 @@ function isValid(pos, c, strict, fromIsValid, fromAlternate, validateOnly, fromC
 			if (commandObj.rewritePosition !== undefined) {
 				maskPos = commandObj.rewritePosition;
 				// commandObj.rewritePosition = undefined;
-				commandObj = true;
+				commandObj = true; // see prevalidation in isValid
 			}
 		}
 		return commandObj;
@@ -629,7 +629,8 @@ function revalidateMask(pos, validTest, fromIsValid, validatedPos) {
 			i;
 		maskset.p = begin; //needed for alternated position after overtype selection
 
-		for (i = lvp; i >= begin; i--) {
+		var clearpos = isSelection.call(inputmask, pos) ? begin : validatedPos;
+		for (i = lvp; i >= clearpos; i--) {
 			maskset.validPositions.splice(i, 1);
 			if (validTest === undefined) delete maskset.tests[i + 1];
 		}

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.9-beta.33",
+  "version": "5.0.9-beta.35",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
   "main": "dist/inputmask.js",
   "exports": {