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

url-join

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-join - npm Package Compare versions

Comparing version 2.0.5 to 3.0.0

2

bower.json
{
"name": "url-join",
"version": "2.0.5",
"version": "3.0.0",
"homepage": "https://github.com/jfromaniello/url-join",

@@ -5,0 +5,0 @@ "authors": [

@@ -11,17 +11,45 @@ (function (name, context, definition) {

function normalize (str, options) {
function normalize (strArray, options) {
var resultArray = [];
// If the first part is a plain protocol, we combine it with the next part.
if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
var first = strArray.shift();
strArray[0] = first + strArray[0];
}
if (startsWith(str, 'file://')) {
// make sure file protocol has max three slashes
str = str.replace(/(\/{0,3})\/*/g, '$1');
// There must be two or three slashes in the file protocol, two slashes in anything else.
if (strArray[0].match(/^file:\/\/\//)) {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1:///');
} else {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1://');
}
for (var i = 0; i < strArray.length; i++) {
var component = strArray[i];
// make sure protocol is followed by two slashes
str = str.replace(/:\//g, '://');
if (typeof component !== 'string') {
component = component && component.toString() || '';
}
// remove consecutive slashes
str = str.replace(/([^:\s\%\3\A])\/+/g, '$1/');
if (i > 0) {
// Removing the starting slashes for each component but the first.
component = component.replace(/^[\/]+/, '');
}
if (i < strArray.length - 1) {
// Removing the ending slashes for each component but the last.
component = component.replace(/[\/]+$/, '');
} else {
// For the last component we will combine multiple slashes to a single one.
component = component.replace(/[\/]+$/, '/');
}
resultArray.push(component);
}
var str = resultArray.join('/');
// Each input component is now separated by a single slash except the possible first plain protocol part.
// remove trailing slash before parameters or hash

@@ -31,3 +59,4 @@ str = str.replace(/\/(\?|&|#[^!])/g, '$1');

// replace ? in parameters with &
str = str.replace(/(\?.+)\?/g, '$1&');
var parts = str.split('?');
str = parts.shift() + (parts.length > 0 ? '?': '') + parts.join('&');

@@ -46,7 +75,6 @@ return str;

}
var joined = [].slice.call(input, 0).join('/');
return normalize(joined, options);
return normalize([].slice.call(input), options);
};
});
{
"name": "url-join",
"version": "2.0.5",
"version": "3.0.0",
"description": "Join urls and normalize as in path.join.",

@@ -5,0 +5,0 @@ "main": "lib/url-join.js",

@@ -75,3 +75,3 @@ var urljoin = require('../lib/url-join');

it.skip('should merge multiple query params properly', function () {
it('should merge multiple query params properly', function () {
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?key=456')

@@ -87,7 +87,3 @@ .should.eql('http://www.google.com/foo/bar?test=123&key=456');

//There is a problem with the capital A and the regex in the replace function
// /([^:\s\%\3\A])\/+/g
// I think the intention of the regex is to avoid replacing two slashes in the query string:
// "?url=http%3A//"
it.skip('should merge slashes in paths correctly', function () {
it('should merge slashes in paths correctly', function () {
urljoin('http://example.org', 'a//', 'b//', 'A//', 'B//')

@@ -97,3 +93,3 @@ .should.eql('http://example.org/a/b/A/B/');

it.skip('should merge colons in paths correctly', function () {
it('should merge colons in paths correctly', function () {
urljoin('http://example.org/', ':foo:', 'bar')

@@ -103,3 +99,3 @@ .should.eql('http://example.org/:foo:/bar');

it.skip('should merge just a simple path without URL correctly', function() {
it('should merge just a simple path without URL correctly', function() {
urljoin('/', 'test')

@@ -114,3 +110,8 @@ .should.eql('/test');

it.skip('should merge slashes in protocol correctly', function () {
it('should merge a path with colon properly', function(){
urljoin('/users/:userId', '/cars/:carId')
.should.eql('/users/:userId/cars/:carId');
});
it('should merge slashes in protocol correctly', function () {
urljoin('http://example.org', 'a')

@@ -125,3 +126,2 @@ .should.eql('http://example.org/a');

//this one is broken
urljoin('file:example.org', 'a')

@@ -128,0 +128,0 @@ .should.eql('file://example.org/a');

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