|
| 1 | +var safe = require('safe-regex'); |
| 2 | +// use atomic group to scape backtracking |
| 3 | +// var regex = process.argv.slice(2).join(' '); |
| 4 | +// console.log(safe(regex)); |
| 5 | +const showPatterns = (arr) => { |
| 6 | + arr.forEach(pattern => { |
| 7 | + // console.log("\r\n*", pattern[0], ":\r\n") |
| 8 | + // console.log(" `" + prepareRegexObject(pattern[1]) + "`", "\r\n") |
| 9 | + |
| 10 | + console.log("\r\n", pattern[0], "=>", "safe:", pattern[2]) |
| 11 | + console.log(prepareRegexObject(pattern[1]), "\r\n") |
| 12 | + }) |
| 13 | +} |
| 14 | +const prepareRegexObject = (p_text) => typeof p_text === "string" ? new RegExp(p_text) : p_text; |
| 15 | +const checkPatterns = (patterns_object) => { |
| 16 | + const safePatterns = []; |
| 17 | + const unSafePatterns = []; |
| 18 | + Object.entries(patterns_object).forEach(pattern => { |
| 19 | + if (safe(prepareRegexObject(pattern[1]))) { |
| 20 | + safePatterns.push([...pattern, true]) |
| 21 | + } else |
| 22 | + unSafePatterns.push([...pattern, false]) |
| 23 | + }) |
| 24 | + console.log("\r\n**********Safe Patterns*******\r\n") |
| 25 | + showPatterns(safePatterns); |
| 26 | + console.log("\r\n\r\n\r\n⚠⚠⚠⚠⚠ Un-Safe Patterns ⚠⚠⚠⚠⚠") |
| 27 | + showPatterns(unSafePatterns); |
| 28 | +} |
| 29 | + |
| 30 | +const patterns = { |
| 31 | + en_label: "^[a-zA-Z0-9-_ ]{0,250}$", |
| 32 | + unicode_label: "^[\\s\\w\\u0600-\\u06FFs]{0,250}$", |
| 33 | + label: "^[\\s\\w\\u0600-\\u06FFs]{0,250}$", |
| 34 | + |
| 35 | + publicKey: "^[\\s\\d\\w]{0,3000}$", |
| 36 | + |
| 37 | + description: "^[\\s\\w\\u0600-\\u06FFs]{0,5000}$", |
| 38 | + |
| 39 | + email: "^[\\w-.]{1,50}@[\\w-.]{1,50}\\.[\\w-.]{1,50}$", |
| 40 | + |
| 41 | + mobile: "^((\\+[0-9]{1,2})|0)9[0-9]{9}$", |
| 42 | + |
| 43 | + number: "^[0-9]*$", |
| 44 | +//^(?<protocol>((ht|f)tp(s?):\/\/))?$ |
| 45 | + // |
| 46 | + link: /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/, |
| 47 | +//^(?<port>:(\d){1,5})?(\/)?([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$ |
| 48 | + complexWord: "^[\\s\\d\\w\\u0600-\\u06FFs_+=:!@#$%^&*()+.\\/\\/-]*$", |
| 49 | + password: "^[\\s\\d\\w\\u0600-\\u06FFs_+=:;!@#$%^&*()+<>,.\\/-]{8,16}$", |
| 50 | + password16: |
| 51 | + "^[\\s\\d\\w\\u0600-\\u06FFs_+=:;!@#$%^&*()+<>,.\\/\\/-]{16,32}$", |
| 52 | + passwordN: "^[\\s\\d\\w\\u0600-\\u06FFs_+=:;!@#$%^&*()+<>,.\\/\\/-]{8,}$", |
| 53 | + alphaNumeric: /^[\w\d]+$/, |
| 54 | + license: "^[\\w\\d]{25}$", |
| 55 | + vpnHexKey: "^[a-fA-F\\d]{64}$", |
| 56 | + vpnHexIV: "^[a-fA-F\\d]{32}$", |
| 57 | + vpnPassword: "^[A-Za-z0-9@#$%^&!+=]{8,16}$" |
| 58 | +}; |
| 59 | +checkPatterns(patterns) |
| 60 | +// var validator = require('validator'); |
| 61 | + |
| 62 | +// validator.isEmail('[email protected]'); //=> true |
| 63 | + |
| 64 | +// const result = validator.isURL("https://emm-develop.pho`enix.mahsan.net/") |
| 65 | +// console.log(result); |
0 commit comments