Comparing version 1.1.0 to 2.0.0
@@ -7,10 +7,21 @@ (function (name, context, definition) { | ||
function startsWith(str, searchString) { | ||
return str.substr(0, searchString.length) === searchString; | ||
} | ||
function normalize (str, options) { | ||
// make sure protocol is followed by two slashes | ||
str = str.replace(/:\//g, '://'); | ||
if (startsWith(str, 'file://')) { | ||
// remove consecutive slashes | ||
str = str.replace(/([^:\s])\/+/g, '$1/'); | ||
// make sure file protocol has max three slashes | ||
str = str.replace(/(\/{0,3})\/*/g, '$1'); | ||
} else { | ||
// make sure protocol is followed by two slashes | ||
str = str.replace(/:\//g, '://'); | ||
// remove consecutive slashes | ||
str = str.replace(/([^:\s])\/+/g, '$1/'); | ||
} | ||
// remove trailing slash before parameters or hash | ||
@@ -17,0 +28,0 @@ str = str.replace(/\/(\?|&|#[^!])/g, '$1'); |
{ | ||
"name": "url-join", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Join urls and normalize as in path.join.", | ||
@@ -5,0 +5,0 @@ "main": "lib/url-join.js", |
@@ -44,2 +44,24 @@ var urljoin = require('../lib/url-join'); | ||
it('should support file protocol urls', function () { | ||
urljoin('file:/', 'android_asset', 'foo/bar') | ||
.should.eql('file://android_asset/foo/bar') | ||
urljoin('file:', '/android_asset', 'foo/bar') | ||
.should.eql('file://android_asset/foo/bar') | ||
}); | ||
it('should support absolute file protocol urls', function () { | ||
urljoin('file:', '///android_asset', 'foo/bar') | ||
.should.eql('file:///android_asset/foo/bar') | ||
urljoin('file:///', 'android_asset', 'foo/bar') | ||
.should.eql('file:///android_asset/foo/bar') | ||
urljoin('file:///', '//android_asset', 'foo/bar') | ||
.should.eql('file:///android_asset/foo/bar') | ||
urljoin('file:///android_asset', 'foo/bar') | ||
.should.eql('file:///android_asset/foo/bar') | ||
}); | ||
it('should merge multiple query params properly', function () { | ||
@@ -46,0 +68,0 @@ urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?key=456') |
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
6916
8
115