🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

parse-uri

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-uri - npm Package Compare versions

Comparing version

to
1.0.11

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/Kikobeats/parse-uri",
"version": "1.0.10",
"version": "1.0.11",
"main": "src/index.js",

@@ -8,0 +8,0 @@ "author": {

@@ -28,15 +28,38 @@ 'use strict'

parser: {
strict: /^(?:([^:/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?))?((((?:[^?#/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#/]*\.[^?#/.]+(?:[?#]|$)))*\/?)?([^?#/]*))(?:\?([^#]*))?(?:#(.*))?)/
strict:
/^(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
loose:
/^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?:\/\/)?([^/?#]*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/
}
}
const m = o.parser[opts.strictMode ? 'strict' : 'loose'].exec(str)
const pattern = opts.strictMode ? o.parser.strict : o.parser.loose
const matches = pattern.exec(str)
if (!matches) return undefined
const uri = {}
let i = 14
uri[o.key[0]] = str
uri[o.key[1]] = matches[1] || ''
uri[o.key[2]] = matches[2] || ''
uri[o.key[8]] = matches[3] || ''
uri[o.key[12]] = matches[4] || ''
uri[o.key[13]] = matches[5] || ''
while (i--) uri[o.key[i]] = m[i] || ''
// Further breakdown and parsing can be done here if needed
// For example, splitting authority into userInfo, host, and port
if (uri[o.key[2]]) {
const authorityPattern =
/^(?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?/
const authorityMatches = authorityPattern.exec(uri[o.key[2]])
if (authorityMatches) {
uri[o.key[3]] = authorityMatches[1] || ''
uri[o.key[4]] = authorityMatches[2] || ''
uri[o.key[5]] = authorityMatches[3] || ''
uri[o.key[6]] = authorityMatches[4] || ''
uri[o.key[7]] = authorityMatches[5] || ''
}
}
uri[o.q.name] = {}
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
uri[o.key[12]].replace(o.q.parser, function (_, $1, $2) {
if ($1) uri[o.q.name][$1] = $2

@@ -43,0 +66,0 @@ })