diff --git a/index.js b/index.js index 134dec9..ba9979e 100644 --- a/index.js +++ b/index.js @@ -160,7 +160,7 @@ function serialize (cmpts, opts) { } if (authority === undefined) { - s = s.replace(/^\/\//, '/%2F') // don't allow the path to start with "//" + s = s.replace(/^\/\//u, '/%2F') // don't allow the path to start with "//" } uriTokens.push(s) @@ -178,7 +178,7 @@ function serialize (cmpts, opts) { return uriTokens.join('') } -const hexLookUp = Array.from({ length: 127 }, (v, k) => /[^!"$&'()*+,.;=_`a-z{}~-]/.test(String.fromCharCode(k))) +const hexLookUp = Array.from({ length: 127 }, (v, k) => /[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(k))) function nonSimpleDomain (value) { let code = 0 @@ -191,7 +191,7 @@ function nonSimpleDomain (value) { return false } -const URI_PARSE = /^(?:([^:/?#]+):)?(?:\/\/((?:([^/?#@]*)@)?(\[[^/?#\]]+\]|[^/?#:]*)(?::(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i +const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u function parse (uri, opts) { const options = Object.assign({}, opts) diff --git a/lib/schemes.js b/lib/schemes.js index c5cd478..45d06fe 100644 --- a/lib/schemes.js +++ b/lib/schemes.js @@ -1,7 +1,7 @@ 'use strict' -const UUID_REG = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ -const URN_REG = /([A-Za-z0-9][A-Za-z0-9-]{0,31}):((?:[A-Za-z0-9()+,\-.:=@;$_!*']|%[0-9A-Fa-f]{2})+)/ +const UUID_REG = /^[\da-f]{8}\b-[\da-f]{4}\b-[\da-f]{4}\b-[\da-f]{4}\b-[\da-f]{12}$/iu +const URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu function isSecure (wsComponents) { return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === 'wss' diff --git a/lib/utils.js b/lib/utils.js index 0716ab9..78134c6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -4,7 +4,7 @@ const { HEX } = require('./scopedChars') function normalizeIPv4 (host) { if (findToken(host, '.') < 3) { return { host, isIPV4: false } } - const matches = host.match(/^(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/) || [] + const matches = host.match(/^(\b[01]?\d{1,2}|\b2[0-4]\d|\b25[0-5])(\.([01]?\d{1,2}|2[0-4]\d|25[0-5])){3}$/u) || [] const [address] = matches if (address) { return { host: stripLeadingZeros(address, '.'), isIPV4: true } @@ -138,10 +138,10 @@ function findToken (str, token) { return ind } -const RDS1 = /^\.\.?\// -const RDS2 = /^\/\.(\/|$)/ -const RDS3 = /^\/\.\.(\/|$)/ -const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/ +const RDS1 = /^\.\.?\//u +const RDS2 = /^\/\.(?:\/|$)/u +const RDS3 = /^\/\.\.(?:\/|$)/u +const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/u function removeDotSegments (input) { const output = []