Comparing version 0.2.2 to 0.2.3
@@ -9,2 +9,3 @@ 'use strict'; | ||
, inherit = { protocol: 1, host: 1, hostname: 1 } | ||
, relativere = /^\/(?!\/)/ | ||
, parts = keys.length; | ||
@@ -62,2 +63,3 @@ | ||
var regexp = new RegExp('\^\(\?:\(\?:\(\(\[\^:\\/\#\\\?\]\+:\)\?\(\?:\(\?:\\/\\/\)\(\?:\(\?:\(\?:\(\[\^:@\\/\#\\\?\]\+\)\(\?:\\:\(\[\^:@\\/\#\\\?\]\*\)\)\?\)@\)\?\(\(\[\^:\\/\#\\\?\\\]\\\[\]\+\|\\\[\[\^\\/\\\]@\#\?\]\+\\\]\)\(\?:\\:\(\[0\-9\]\+\)\)\?\)\)\?\)\?\)\?\(\(\?:\\/\?\(\?:\[\^\\/\\\?\#\]\+\\/\+\)\*\)\(\?:\[\^\\\?\#\]\*\)\)\)\?\(\\\?\[\^\#\]\+\)\?\)\(\#\.\*\)\?') | ||
, relative = relativere.test(address) | ||
, bits = regexp.exec(address) | ||
@@ -94,3 +96,3 @@ , type = typeof location | ||
url[key] = bits[i] || (key in inherit ? location[key] || '' : ''); | ||
url[key] = bits[i] || (key in inherit || ('port' === key && relative) ? location[key] || '' : ''); | ||
@@ -97,0 +99,0 @@ // |
{ | ||
"name": "url-parse", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Parse URL in node using the URL module and in the browser using the DOM", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha --reporter spec --ui bdd test.js", | ||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter spec --ui bdd test.js", | ||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --ui bdd test.js", | ||
"test": "mocha --reporter spec --ui bdd ./test.js", | ||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter spec --ui bdd ./test.js", | ||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --ui bdd ./test.js", | ||
"browserify": "mkdir dist && browserify index.js -o dist/url-parse.js --standalone URLParse", | ||
"phantomjs": "mocha-phantomjs --reporter spec --ui bdd test.js", | ||
"phantomjs": "mochify --reporter spec --ui bdd ./test.js", | ||
"testling": "testling -u" | ||
@@ -32,3 +32,3 @@ }, | ||
"mocha": "2.0.x", | ||
"mocha-phantomjs": "3.5.x", | ||
"mochify": "2.1.x", | ||
"pre-commit": "0.0.x", | ||
@@ -35,0 +35,0 @@ "testling": "1.7.x" |
74
test.js
@@ -112,8 +112,6 @@ describe('url-parse', function () { | ||
it('does not inherit auth from source object', function () { | ||
var data = parse('/foo', parse('http://foo:bar@sub.example.com')); | ||
it('accepts a string as source argument', function () { | ||
var data = parse('/foo', 'http://sub.example.com/bar?foo=bar#hash'); | ||
assume(data.port).equals(''); | ||
assume(data.username).equals(''); | ||
assume(data.password).equals(''); | ||
assume(data.host).equals('sub.example.com'); | ||
@@ -123,32 +121,54 @@ assume(data.href).equals('http://sub.example.com/foo'); | ||
it('does not inherit hashes and query strings from source object', function () { | ||
var data = parse('/foo', parse('http://sub.example.com/bar?foo=bar#hash')); | ||
describe('inheritance', function () { | ||
it('does not inherit port numbers for non relative urls', function () { | ||
var data = parse('http://localhost', parse('http://sub.example.com:808/')); | ||
assume(data.port).equals(''); | ||
assume(data.host).equals('sub.example.com'); | ||
assume(data.href).equals('http://sub.example.com/foo'); | ||
}); | ||
assume(data.port).equals(''); | ||
assume(data.host).equals('localhost'); | ||
assume(data.href).equals('http://localhost'); | ||
}); | ||
it('does not inherit pathnames from the source', function () { | ||
var data = parse('http://localhost', parse('http://foo:bar@sub.example.com/bar?foo=bar#hash')); | ||
it('does inherit port numbers from relative urls', function () { | ||
var data = parse('/foo', parse('http://sub.example.com:808/')); | ||
assume(data.port).equals(''); | ||
assume(data.host).equals('localhost'); | ||
assume(data.href).equals('http://localhost'); | ||
}); | ||
assume(data.port).equals('808'); | ||
assume(data.hostname).equals('sub.example.com'); | ||
assume(data.host).equals('sub.example.com:808'); | ||
assume(data.href).equals('http://sub.example.com:808/foo'); | ||
}); | ||
it('does not inherit port numbers', function () { | ||
var data = parse('http://localhost', parse('http://sub.example.com:808/')); | ||
it('inherits protocol for relative protocols', function () { | ||
var data = parse('//foo.com/foo', parse('http://sub.example.com:808/')); | ||
assume(data.port).equals(''); | ||
assume(data.host).equals('localhost'); | ||
assume(data.href).equals('http://localhost'); | ||
}); | ||
assume(data.port).equals(''); | ||
assume(data.host).equals('foo.com'); | ||
assume(data.protocol).equals('http:'); | ||
assume(data.href).equals('http://foo.com/foo'); | ||
}); | ||
it('accepts a string as source argument', function () { | ||
var data = parse('/foo', 'http://sub.example.com/bar?foo=bar#hash'); | ||
it('does not inherit pathnames from the source', function () { | ||
var data = parse('http://localhost', parse('http://foo:bar@sub.example.com/bar?foo=bar#hash')); | ||
assume(data.port).equals(''); | ||
assume(data.host).equals('sub.example.com'); | ||
assume(data.href).equals('http://sub.example.com/foo'); | ||
assume(data.port).equals(''); | ||
assume(data.host).equals('localhost'); | ||
assume(data.href).equals('http://localhost'); | ||
}); | ||
it('does not inherit hashes and query strings from source object', function () { | ||
var data = parse('/foo', parse('http://sub.example.com/bar?foo=bar#hash')); | ||
assume(data.port).equals(''); | ||
assume(data.host).equals('sub.example.com'); | ||
assume(data.href).equals('http://sub.example.com/foo'); | ||
}); | ||
it('does not inherit auth from source object', function () { | ||
var data = parse('/foo', parse('http://foo:bar@sub.example.com')); | ||
assume(data.port).equals(''); | ||
assume(data.username).equals(''); | ||
assume(data.password).equals(''); | ||
assume(data.host).equals('sub.example.com'); | ||
assume(data.href).equals('http://sub.example.com/foo'); | ||
}); | ||
}); | ||
@@ -155,0 +175,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25859
494
8