From a4f5d8e72ccf090985ce70762fbe00e1cc4e8710 Mon Sep 17 00:00:00 2001 From: molaga Date: Sun, 8 Dec 2019 09:14:13 +0200 Subject: [PATCH 1/2] Bugfix - Wrong IP address validation https://github.com/validatorjs/validator.js/issues/1209 --- es/lib/alpha.js | 4 ++-- es/lib/isIP.js | 2 +- es/lib/isMobilePhone.js | 2 ++ es/lib/isURL.js | 11 +++++++++++ lib/alpha.js | 4 ++-- lib/isIP.js | 2 +- lib/isMobilePhone.js | 2 ++ src/lib/isIP.js | 2 +- validator.js | 19 ++++++++++++++++--- validator.min.js | 2 +- 10 files changed, 39 insertions(+), 11 deletions(-) diff --git a/es/lib/alpha.js b/es/lib/alpha.js index 4fa84c1c3..f7e364b84 100644 --- a/es/lib/alpha.js +++ b/es/lib/alpha.js @@ -13,7 +13,7 @@ export var alpha = { 'nn-NO': /^[A-ZÆØÅ]+$/i, 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, - 'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i, + 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, 'ru-RU': /^[А-ЯЁ]+$/i, 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, @@ -42,7 +42,7 @@ export var alphanumeric = { 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i, 'nn-NO': /^[0-9A-ZÆØÅ]+$/i, 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i, - 'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i, + 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, 'ru-RU': /^[0-9А-ЯЁ]+$/i, 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, diff --git a/es/lib/isIP.js b/es/lib/isIP.js index db05e7369..9280d8766 100644 --- a/es/lib/isIP.js +++ b/es/lib/isIP.js @@ -29,7 +29,7 @@ import assertString from './util/assertString'; to the 5th link, and "interface10" belongs to the 10th organization. * * */ -var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; +var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; var ipv6Block = /^[0-9A-F]{1,4}$/i; export default function isIP(str) { var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; diff --git a/es/lib/isMobilePhone.js b/es/lib/isMobilePhone.js index badd00854..9f8e1684d 100644 --- a/es/lib/isMobilePhone.js +++ b/es/lib/isMobilePhone.js @@ -25,6 +25,7 @@ var phones = { 'en-GG': /^(\+?44|0)1481\d{6}$/, 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/, 'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/, + 'en-MO': /^(\+?853\-?)?[268]\d{3}\-?\d{4}$/, 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, 'en-IN': /^(\+?91|0)?[6789]\d{9}$/, 'en-KE': /^(\+?254|0)(7|1)\d{8}$/, @@ -94,6 +95,7 @@ var phones = { phones['en-CA'] = phones['en-US']; phones['fr-BE'] = phones['nl-BE']; phones['zh-HK'] = phones['en-HK']; +phones['zh-MO'] = phones['en-MO']; export default function isMobilePhone(str, locale, options) { assertString(str); diff --git a/es/lib/isURL.js b/es/lib/isURL.js index d4ff49e30..72a79fadd 100644 --- a/es/lib/isURL.js +++ b/es/lib/isURL.js @@ -2,6 +2,17 @@ import assertString from './util/assertString'; import isFQDN from './isFQDN'; import isIP from './isIP'; import merge from './util/merge'; +/* +options for isURL method + +require_protocol - if set as true isURL will return false if protocol is not present in the URL +require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option +protocols - valid protocols can be modified with this option +require_host - if set as false isURL will not check if host is present in the URL +allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed + +*/ + var default_url_options = { protocols: ['http', 'https', 'ftp'], require_tld: true, diff --git a/lib/alpha.js b/lib/alpha.js index a8c1be490..b5d38083c 100644 --- a/lib/alpha.js +++ b/lib/alpha.js @@ -19,7 +19,7 @@ var alpha = { 'nn-NO': /^[A-ZÆØÅ]+$/i, 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, - 'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i, + 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, 'ru-RU': /^[А-ЯЁ]+$/i, 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, @@ -49,7 +49,7 @@ var alphanumeric = { 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i, 'nn-NO': /^[0-9A-ZÆØÅ]+$/i, 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i, - 'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i, + 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, 'ru-RU': /^[0-9А-ЯЁ]+$/i, 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, diff --git a/lib/isIP.js b/lib/isIP.js index 13f7ebc3f..b5a924cfd 100644 --- a/lib/isIP.js +++ b/lib/isIP.js @@ -38,7 +38,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs to the 5th link, and "interface10" belongs to the 10th organization. * * */ -var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; +var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; var ipv6Block = /^[0-9A-F]{1,4}$/i; function isIP(str) { diff --git a/lib/isMobilePhone.js b/lib/isMobilePhone.js index 51051c2a9..0510c2835 100644 --- a/lib/isMobilePhone.js +++ b/lib/isMobilePhone.js @@ -35,6 +35,7 @@ var phones = { 'en-GG': /^(\+?44|0)1481\d{6}$/, 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/, 'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/, + 'en-MO': /^(\+?853\-?)?[268]\d{3}\-?\d{4}$/, 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, 'en-IN': /^(\+?91|0)?[6789]\d{9}$/, 'en-KE': /^(\+?254|0)(7|1)\d{8}$/, @@ -104,6 +105,7 @@ var phones = { phones['en-CA'] = phones['en-US']; phones['fr-BE'] = phones['nl-BE']; phones['zh-HK'] = phones['en-HK']; +phones['zh-MO'] = phones['en-MO']; function isMobilePhone(str, locale, options) { (0, _assertString.default)(str); diff --git a/src/lib/isIP.js b/src/lib/isIP.js index 38141760a..a9a805781 100644 --- a/src/lib/isIP.js +++ b/src/lib/isIP.js @@ -28,7 +28,7 @@ import assertString from './util/assertString'; where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs to the 5th link, and "interface10" belongs to the 10th organization. * * */ -const ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; +const ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; const ipv6Block = /^[0-9A-F]{1,4}$/i; export default function isIP(str, version = '') { diff --git a/validator.js b/validator.js index e311e5b69..48ee66bad 100644 --- a/validator.js +++ b/validator.js @@ -286,7 +286,7 @@ function isFQDN(str, options) { to the 5th link, and "interface10" belongs to the 10th organization. * * */ -var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; +var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; var ipv6Block = /^[0-9A-F]{1,4}$/i; function isIP(str) { var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; @@ -548,6 +548,17 @@ function isEmail(str, options) { return true; } +/* +options for isURL method + +require_protocol - if set as true isURL will return false if protocol is not present in the URL +require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option +protocols - valid protocols can be modified with this option +require_host - if set as false isURL will not check if host is present in the URL +allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed + +*/ + var default_url_options = { protocols: ['http', 'https', 'ftp'], require_tld: true, @@ -736,7 +747,7 @@ var alpha = { 'nn-NO': /^[A-ZÆØÅ]+$/i, 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, - 'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i, + 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, 'ru-RU': /^[А-ЯЁ]+$/i, 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, @@ -765,7 +776,7 @@ var alphanumeric = { 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i, 'nn-NO': /^[0-9A-ZÆØÅ]+$/i, 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i, - 'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i, + 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i, 'ru-RU': /^[0-9А-ЯЁ]+$/i, 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i, 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, @@ -1438,6 +1449,7 @@ var phones = { 'en-GG': /^(\+?44|0)1481\d{6}$/, 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/, 'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/, + 'en-MO': /^(\+?853\-?)?[268]\d{3}\-?\d{4}$/, 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, 'en-IN': /^(\+?91|0)?[6789]\d{9}$/, 'en-KE': /^(\+?254|0)(7|1)\d{8}$/, @@ -1507,6 +1519,7 @@ var phones = { phones['en-CA'] = phones['en-US']; phones['fr-BE'] = phones['nl-BE']; phones['zh-HK'] = phones['en-HK']; +phones['zh-MO'] = phones['en-MO']; function isMobilePhone(str, locale, options) { assertString(str); diff --git a/validator.min.js b/validator.min.js index 5004d85f6..1d17d4bb4 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,4 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.validator=e()}(this,function(){"use strict";function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function g(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if(!(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)))return;var r=[],n=!0,o=!1,i=void 0;try{for(var a,s=t[Symbol.iterator]();!(n=(a=s.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==s.return||s.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function $(t){var e;if(!("string"==typeof t||t instanceof String))throw e=null===t?"null":"object"===(e=a(t))&&t.constructor&&t.constructor.hasOwnProperty("name")?t.constructor.name:"a ".concat(e),new TypeError("Expected string but received ".concat(e,"."))}function o(t){return $(t),t=Date.parse(t),isNaN(t)?null:new Date(t)}function r(t){return $(t),parseFloat(t)}function i(t){return"object"===a(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function m(t,e){var r=0a)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(n.shift(),n.shift(),o=!0):"::"===t.substr(t.length-2)&&(n.pop(),n.pop(),o=!0);for(var s=0;s$/i,E=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,x=/^[a-z\d]+$/,M=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,w=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,N=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;var d={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},f=/^\[([^\]]+)\](?::([0-9]+))?$/;function p(t,e){for(var r=0;r=e.min,o=!e.hasOwnProperty("max")||t<=e.max,i=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&o&&i&&a}var V=/^[\x00-\x7F]+$/;var j=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var J=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var q=/[^\x00-\x7F]/;var Q=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function X(t,e){return t.some(function(t){return e===t})}var tt=Object.keys(T);var et={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},rt=["","-","+"];var nt=/^(0x|0h)?[0-9A-F]+$/i;function ot(t){return $(t),nt.test(t)}var it=/^(0o)?[0-7]+$/i;var at=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;var st=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var lt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var ut=/^[a-f0-9]{32}$/;var ct={md5:32,md4:32,sha1:40,sha256:64,sha384:96,sha512:128,ripemd128:32,ripemd160:40,tiger128:32,tiger160:40,tiger192:48,crc32:8,crc32b:8};var dt=/^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/;var ft={ignore_whitespace:!1};var pt={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};var ht=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;var At={ES:function(t){$(t);var e={X:0,Y:1,Z:2},r=t.trim().toUpperCase();if(!/^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/.test(r))return!1;var n=r.slice(0,-1).replace(/[X,Y,Z]/g,function(t){return e[t]});return r.endsWith(["T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E"][n%23])},"he-IL":function(t){var e=t.trim();if(!/^\d{9}$/.test(e))return!1;for(var r,n=e,o=0,i=0;i]/.test(r)){if(!e)return!1;if(!(r.split('"').length===r.split('\\"').length))return!1}return!0}(n))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,n,o,i,a,s,l,u;if(e=m(e,d),1<(l=(t=(l=(t=(l=t.split("#")).shift()).split("?")).shift()).split("://")).length){if(r=l.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(r))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;l[0]=t.substr(2)}}if(""===(t=l.join("://")))return!1;if(""===(t=(l=t.split("/")).shift())&&!e.require_host)return!0;if(1<(l=t.split("@")).length){if(e.disallow_auth)return!1;if(0<=(n=l.shift()).indexOf(":")&&2=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)},isFloatLocales:tt,isDecimal:function(t,e){if($(t),(e=m(e,et)).locale in T)return!X(rt,t.replace(/ /g,""))&&function(t){return new RegExp("^[-+]?([0-9]+)?(\\".concat(T[t.locale],"[0-9]{").concat(t.decimal_digits,"})").concat(t.force_decimal?"":"?","$"))}(e).test(t);throw new Error("Invalid locale '".concat(e.locale,"'"))},isHexadecimal:ot,isOctal:function(t){return $(t),it.test(t)},isDivisibleBy:function(t,e){return $(t),r(t)%parseInt(e,10)==0},isHexColor:function(t){return $(t),at.test(t)},isISRC:function(t){return $(t),st.test(t)},isMD5:function(t){return $(t),ut.test(t)},isHash:function(t,e){return $(t),new RegExp("^[a-fA-F0-9]{".concat(ct[e],"}$")).test(t)},isJWT:function(t){return $(t),dt.test(t)},isJSON:function(t){$(t);try{var e=JSON.parse(t);return!!e&&"object"===a(e)}catch(t){}return!1},isEmpty:function(t,e){return $(t),0===((e=m(e,ft)).ignore_whitespace?t.trim().length:t.length)},isLength:function(t,e){var r,n;$(t),n="object"===a(e)?(r=e.min||0,e.max):(r=e||0,arguments[2]);var o=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-o.length;return r<=i&&(void 0===n||i<=n)},isByteLength:v,isUUID:function(t){var e=1/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return $(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return $(t),Qt(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return $(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Qt,isWhitelisted:function(t,e){$(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=m(e,Xt);var r=t.split("@"),n=r.pop(),o=[r.join("@"),n];if(o[1]=o[1].toLowerCase(),"gmail.com"===o[1]||"googlemail.com"===o[1]){if(e.gmail_remove_subaddress&&(o[0]=o[0].split("+")[0]),e.gmail_remove_dots&&(o[0]=o[0].replace(/\.+/g,oe)),!o[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(o[0]=o[0].toLowerCase()),o[1]=e.gmail_convert_googlemaildotcom?"gmail.com":o[1]}else if(0<=te.indexOf(o[1])){if(e.icloud_remove_subaddress&&(o[0]=o[0].split("+")[0]),!o[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(o[0]=o[0].toLowerCase())}else if(0<=ee.indexOf(o[1])){if(e.outlookdotcom_remove_subaddress&&(o[0]=o[0].split("+")[0]),!o[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(o[0]=o[0].toLowerCase())}else if(0<=re.indexOf(o[1])){if(e.yahoo_remove_subaddress){var i=o[0].split("-");o[0]=1a)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(n.shift(),n.shift(),o=!0):"::"===t.substr(t.length-2)&&(n.pop(),n.pop(),o=!0);for(var s=0;s$/i,E=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,M=/^[a-z\d]+$/,x=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,w=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,N=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;var d={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},f=/^\[([^\]]+)\](?::([0-9]+))?$/;function h(t,e){for(var r=0;r=e.min,o=!e.hasOwnProperty("max")||t<=e.max,i=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&n&&o&&i&&a}var V=/^[\x00-\x7F]+$/;var j=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var J=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var q=/[^\x00-\x7F]/;var Q=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;function X(t,e){return t.some(function(t){return e===t})}var tt=Object.keys(T);var et={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},rt=["","-","+"];var nt=/^(0x|0h)?[0-9A-F]+$/i;function ot(t){return $(t),nt.test(t)}var it=/^(0o)?[0-7]+$/i;var at=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;var st=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var lt=/^[A-z]{4}[A-z]{2}\w{2}(\w{3})?$/;var ut=/^[a-f0-9]{32}$/;var ct={md5:32,md4:32,sha1:40,sha256:64,sha384:96,sha512:128,ripemd128:32,ripemd160:40,tiger128:32,tiger160:40,tiger192:48,crc32:8,crc32b:8};var dt=/^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/;var ft={ignore_whitespace:!1};var ht={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};var pt=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;var At={ES:function(t){$(t);var e={X:0,Y:1,Z:2},r=t.trim().toUpperCase();if(!/^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/.test(r))return!1;var n=r.slice(0,-1).replace(/[X,Y,Z]/g,function(t){return e[t]});return r.endsWith(["T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E"][n%23])},"he-IL":function(t){var e=t.trim();if(!/^\d{9}$/.test(e))return!1;for(var r,n=e,o=0,i=0;i]/.test(r)){if(!e)return!1;if(!(r.split('"').length===r.split('\\"').length))return!1}return!0}(n))return!1}else if(e.require_display_name)return!1}if(!e.ignore_max_length&&254]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,n,o,i,a,s,l,u;if(e=m(e,d),1<(l=(t=(l=(t=(l=t.split("#")).shift()).split("?")).shift()).split("://")).length){if(r=l.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(r))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;l[0]=t.substr(2)}}if(""===(t=l.join("://")))return!1;if(""===(t=(l=t.split("/")).shift())&&!e.require_host)return!0;if(1<(l=t.split("@")).length){if(e.disallow_auth)return!1;if(0<=(n=l.shift()).indexOf(":")&&2=e.min)&&(!e.hasOwnProperty("max")||n<=e.max)&&(!e.hasOwnProperty("lt")||ne.gt)},isFloatLocales:tt,isDecimal:function(t,e){if($(t),(e=m(e,et)).locale in T)return!X(rt,t.replace(/ /g,""))&&(r=e,new RegExp("^[-+]?([0-9]+)?(\\".concat(T[r.locale],"[0-9]{").concat(r.decimal_digits,"})").concat(r.force_decimal?"":"?","$"))).test(t);var r;throw new Error("Invalid locale '".concat(e.locale,"'"))},isHexadecimal:ot,isOctal:function(t){return $(t),it.test(t)},isDivisibleBy:function(t,e){return $(t),r(t)%parseInt(e,10)==0},isHexColor:function(t){return $(t),at.test(t)},isISRC:function(t){return $(t),st.test(t)},isMD5:function(t){return $(t),ut.test(t)},isHash:function(t,e){return $(t),new RegExp("^[a-fA-F0-9]{".concat(ct[e],"}$")).test(t)},isJWT:function(t){return $(t),dt.test(t)},isJSON:function(t){$(t);try{var e=JSON.parse(t);return!!e&&"object"===a(e)}catch(t){}return!1},isEmpty:function(t,e){return $(t),0===((e=m(e,ft)).ignore_whitespace?t.trim().length:t.length)},isLength:function(t,e){var r,n;$(t),n="object"===a(e)?(r=e.min||0,e.max):(r=e||0,arguments[2]);var o=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-o.length;return r<=i&&(void 0===n||i<=n)},isByteLength:v,isUUID:function(t){var e=1/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return $(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return $(t),Qt(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return $(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Qt,isWhitelisted:function(t,e){$(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=m(e,Xt);var r=t.split("@"),n=r.pop(),o=[r.join("@"),n];if(o[1]=o[1].toLowerCase(),"gmail.com"===o[1]||"googlemail.com"===o[1]){if(e.gmail_remove_subaddress&&(o[0]=o[0].split("+")[0]),e.gmail_remove_dots&&(o[0]=o[0].replace(/\.+/g,oe)),!o[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(o[0]=o[0].toLowerCase()),o[1]=e.gmail_convert_googlemaildotcom?"gmail.com":o[1]}else if(0<=te.indexOf(o[1])){if(e.icloud_remove_subaddress&&(o[0]=o[0].split("+")[0]),!o[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(o[0]=o[0].toLowerCase())}else if(0<=ee.indexOf(o[1])){if(e.outlookdotcom_remove_subaddress&&(o[0]=o[0].split("+")[0]),!o[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(o[0]=o[0].toLowerCase())}else if(0<=re.indexOf(o[1])){if(e.yahoo_remove_subaddress){var i=o[0].split("-");o[0]=1 Date: Tue, 11 Feb 2020 12:03:22 +0200 Subject: [PATCH 2/2] Add tests for IPv4 --- test/validators.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/validators.js b/test/validators.js index f660f0f28..fc9b1446f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -734,11 +734,16 @@ describe('Validators', () => { '0.0.0.0', '255.255.255.255', '1.2.3.4', + '255.0.0.1', + '0.0.1.1', ], invalid: [ '::1', '2001:db8:0000:1:1:1:1:1', '::ffff:127.0.0.1', + '137.132.10.01', + '0.256.0.256', + '255.256.255.256', ], }); test({