diff --git a/package-lock.json b/package-lock.json index 8d0fcc1..19a4ff7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,7 +35,6 @@ "slugify": "^1.6.6", "through2": "^4.0.2", "thumbsup-downsize": "^2.5.1", - "url-join": "^4.0.1", "yargs": "^17.7.2", "zen-observable": "^0.10.0" }, @@ -6655,11 +6654,6 @@ "punycode": "^2.1.0" } }, - "node_modules/url-join": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", - "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" - }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -12054,11 +12048,6 @@ "punycode": "^2.1.0" } }, - "url-join": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", - "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" - }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index db4d147..2ae7137 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "slugify": "^1.6.6", "through2": "^4.0.2", "thumbsup-downsize": "^2.5.1", - "url-join": "^4.0.1", "yargs": "^17.7.2", "zen-observable": "^0.10.0" }, diff --git a/src/model/structure.js b/src/model/structure.js index a33b321..742bba3 100644 --- a/src/model/structure.js +++ b/src/model/structure.js @@ -1,5 +1,5 @@ const path = require('path') -const urljoin = require('url-join') +const URL = require('url').URL const url = require('./url') const BROWSER_SUPPORTED_EXT = /(jpg|jpeg|png|gif)$/i @@ -53,7 +53,8 @@ function photoExtension (filepath) { function join (prefix, filepath) { if (prefix.match(/^(http|https|file):\/\//)) { - return urljoin(prefix, url.fromPath(filepath)) + const safePrefix = prefix.endsWith('/') ? prefix : (prefix + '/') + return new URL(url.fromPath(filepath), safePrefix).href } else { return path.join(prefix, filepath) } diff --git a/test/model/structure.spec.js b/test/model/structure.spec.js index 5fe4dff..1d1228c 100644 --- a/test/model/structure.spec.js +++ b/test/model/structure.spec.js @@ -76,6 +76,11 @@ describe('Structure', () => { should(res).eql(ospath('../../holidays/IMG_0001.jpg')) }) + it('can use a relative file system link ending with a slash', () => { + const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: '../../' }) + should(res).eql(ospath('../../holidays/IMG_0001.jpg')) + }) + itLinux('can use an absolute file system link', () => { const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: '/media' }) should(res).eql('/media/holidays/IMG_0001.jpg') @@ -91,6 +96,11 @@ describe('Structure', () => { should(res).eql('C:\\media\\holidays\\IMG_0001.jpg') }) + itWindows('can use an absolute file system link ending with a backslash', () => { + const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'C:\\media\\' }) + should(res).eql('C:\\media\\holidays\\IMG_0001.jpg') + }) + itWindows('can use a file:// system link', () => { const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'file://C:/media' }) should(res).eql('file://C:/media/holidays/IMG_0001.jpg') @@ -100,6 +110,16 @@ describe('Structure', () => { const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'http://test.com' }) should(res).eql('http://test.com/holidays/IMG_0001.jpg') }) + + it('can use a remote HTTP link with a subfolder', () => { + const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'http://test.com/folder' }) + should(res).eql('http://test.com/folder/holidays/IMG_0001.jpg') + }) + + it('can use a remote HTTP link ending with a slash', () => { + const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'http://test.com/folder/' }) + should(res).eql('http://test.com/folder/holidays/IMG_0001.jpg') + }) }) describe('suffix', () => {