Socket
Socket
Sign inDemoInstall

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 1.1.0 to 2.0.0

LICENSE

19

lib/url-join.js

@@ -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')

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