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

url-parse

Package Overview
Dependencies
Maintainers
2
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-parse - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

45

index.js

@@ -11,2 +11,33 @@ 'use strict';

//
// Story time children:
//
// FireFox 34 has some problems with their Regular Expression engine and
// executing a RegExp can cause a `too much recursion` error. We initially fixed
// this by moving the Regular Expression in the URL constructor so it's created
// every single time. This fixed it for some URL's but the more complex the
// URL's get the easier it is to trigger. Complexer URL like:
//
// https://www.mozilla.org/en-US/firefox/34.0/whatsnew/?oldversion=33.1
//
// Still triggered the recursion error. After talking with Chrome and FireFox
// engineers it seemed to be caused by:
//
// https://code.google.com/p/v8/issues/detail?id=430
//
// As FireFox started using Chrome's RegExp engine. After testing various of
// workarounds I finally stumbled upon this gem, use new RegExp as it sometimes
// behaves different then a RegExp literal.
//
// Steps for compiling the new RegExp:
//
// 1. Take the regular RegExp as seen below.
// 2. Escape the RegExp using XRegExp.escape from http://xregexp.com/tests/
// 3. ??
// 4. Profit.
//
// RegExp source: /^(?:(?:(([^:\/#\?]+:)?(?:(?:\/\/)(?:(?:(?:([^:@\/#\?]+)(?:\:([^:@\/#\?]*))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?/
//
var regexp = new RegExp('\^\(\?:\(\?:\(\(\[\^:\\/\#\\\?\]\+:\)\?\(\?:\(\?:\\/\\/\)\(\?:\(\?:\(\?:\(\[\^:@\\/\#\\\?\]\+\)\(\?:\\:\(\[\^:@\\/\#\\\?\]\*\)\)\?\)@\)\?\(\(\[\^:\\/\#\\\?\\\]\\\[\]\+\|\\\[\[\^\\/\\\]@\#\?\]\+\\\]\)\(\?:\\:\(\[0\-9\]\+\)\)\?\)\)\?\)\?\)\?\(\(\?:\\/\?\(\?:\[\^\\/\\\?\#\]\+\\/\+\)\*\)\(\?:\[\^\\\?\#\]\*\)\)\)\?\(\\\?\[\^\#\]\+\)\?\)\(\#\.\*\)\?');
/**

@@ -28,17 +59,7 @@ * The actual URL instance. Instead of returning an object we've opted-in to

//
// Inline the massive regular expression because it causes issues in FireFox
// because our `exec` usage in this function. Normally there should be no side
// affects because we're not doing global matching so the lastIndex of regular
// expression should stay the same but it's causing `too much recursion`
// errors in FireFox when calling the parse method for a second time. Now,
// with great pleasure I introduce to you:
//
// MOARE: Mother Of All Regular Expressions.
//
var regexp = /^(?:(?:(([^:\/#\?]+:)?(?:(?:\/\/)(?:(?:(?:([^:@\/#\?]+)(?:\:([^:@\/#\?]*))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?/
, bits = regexp.exec(address)
var bits = regexp.exec(address)
, type = typeof location
, url = this
, i = 0
, bits
, key;

@@ -45,0 +66,0 @@

{
"name": "url-parse",
"version": "0.2.0",
"version": "0.2.1",
"description": "Parse URL in node using the URL module and in the browser using the DOM",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -64,2 +64,10 @@ describe('url-parse', function () {

it('can parse complex urls multiple times without errors', function () {
var url = 'https://www.mozilla.org/en-US/firefox/34.0/whatsnew/?oldversion=33.1';
for (var i = 0; i < 100; i++) {
parse(url);
}
});
it('converts hostname to lowercase', function () {

@@ -66,0 +74,0 @@ var url = 'HTTP://fOo.eXaMPle.com';

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