Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parseurl

Package Overview
Dependencies
Maintainers
6
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parseurl - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

HISTORY.md

72

index.js
var parse = require('url').parse;
/**
* Module dependencies.
*/
var url = require('url')
var parse = url.parse
var Url = url.Url
/**
* Pattern for a simple path case.
* See: https://github.com/joyent/node/pull/7878
*/
var simplePathRegExp = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/
var tryFastRegExp = /^\/[^\\#]*$/
/**
* Parse the `req` url with memoization.

@@ -9,19 +23,53 @@ *

* @return {Object}
* @api private
* @api public
*/
module.exports = function parseUrl(req){
var parsed = req._parsedUrl;
if (parsed && parsed.href == req.url) {
return parsed;
} else {
parsed = parse(req.url);
var parsed = req._parsedUrl
if (parsed.auth && !parsed.protocol && ~parsed.href.indexOf('//')) {
// This parses pathnames, and a strange pathname like //r@e should work
parsed = parse(req.url.replace(/@/g, '%40'));
}
if (parsed instanceof Url && parsed.href === req.url) {
return parsed
}
return req._parsedUrl = parsed;
parsed = fastparse(req.url)
if (parsed.auth && !parsed.protocol && parsed.href.indexOf('//') !== -1) {
// This parses pathnames, and a strange pathname like //r@e should work
parsed = fastparse(req.url.replace(/@/g, '%40'))
}
return req._parsedUrl = parsed
};
/**
* Parse the `str` url with fast-path short-cut.
*
* @param {string} str
* @return {Object}
* @api private
*/
function fastparse(str) {
if (typeof str === 'string' && tryFastRegExp.test(str)) {
// Try fast path regexp
// See: https://github.com/joyent/node/pull/7878
var simplePath = simplePathRegExp.exec(str)
// Construct simple URL
if (simplePath) {
var url = new Url()
url.path = str
url.href = str
url.pathname = simplePath[1]
if (simplePath[2]) {
url.search = simplePath[2];
url.query = url.search.substr(1);
}
return url
}
}
return parse(str)
}

2

package.json
{
"name": "parseurl",
"description": "parse a url with memoization",
"version": "1.0.1",
"version": "1.1.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Jonathan Ong",

@@ -7,5 +7,5 @@ # parseurl

### var pathname = parseurl(req)
### var parsedUrl = parseurl(req)
`pathname` can then be passed to a router or something.
`parsedUrl` is basically a `url.parse()` object.

@@ -35,2 +35,2 @@ ## LICENSE

TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc