Skip to content

Commit c35b16a

Browse files
authored
Remove joinPaths function (#26833)
Extract from #25940. `assetUrlPrefix` is guaranteed to not contain trailing slashes, making this function unneeded.
1 parent 19a1e1b commit c35b16a

File tree

3 files changed

+2
-53
lines changed

3 files changed

+2
-53
lines changed

web_src/js/bootstrap.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import {joinPaths} from './utils.js';
2-
31
// DO NOT IMPORT window.config HERE!
42
// to make sure the error handler always works, we should never import `window.config`, because some user's custom template breaks it.
53

64
// This sets up the URL prefix used in webpack's chunk loading.
75
// This file must be imported before any lazy-loading is being attempted.
8-
__webpack_public_path__ = joinPaths(window?.config?.assetUrlPrefix ?? '/', '/');
6+
__webpack_public_path__ = `${window.config?.assetUrlPrefix ?? '/assets'}/`;
97

108
export function showGlobalErrorMessage(msg) {
119
const pageContent = document.querySelector('.page-content');

web_src/js/utils.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ export function extname(path = '') {
1111
return ext || '';
1212
}
1313

14-
// join a list of path segments with slashes, ensuring no double slashes
15-
export function joinPaths(...parts) {
16-
let str = '';
17-
for (const part of parts) {
18-
if (!part) continue;
19-
str = !str ? part : `${str.replace(/\/$/, '')}/${part.replace(/^\//, '')}`;
20-
}
21-
return str;
22-
}
23-
2414
// test whether a variable is an object
2515
export function isObject(obj) {
2616
return Object.prototype.toString.call(obj) === '[object Object]';

web_src/js/utils.test.js

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {expect, test} from 'vitest';
22
import {
3-
basename, extname, isObject, stripTags, joinPaths, parseIssueHref,
3+
basename, extname, isObject, stripTags, parseIssueHref,
44
parseUrl, translateMonth, translateDay, blobToDataURI,
55
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64,
66
} from './utils.js';
@@ -18,45 +18,6 @@ test('extname', () => {
1818
expect(extname('file.js')).toEqual('.js');
1919
});
2020

21-
test('joinPaths', () => {
22-
expect(joinPaths('', '')).toEqual('');
23-
expect(joinPaths('', 'b')).toEqual('b');
24-
expect(joinPaths('', '/b')).toEqual('/b');
25-
expect(joinPaths('', '/b/')).toEqual('/b/');
26-
expect(joinPaths('a', '')).toEqual('a');
27-
expect(joinPaths('/a', '')).toEqual('/a');
28-
expect(joinPaths('/a/', '')).toEqual('/a/');
29-
expect(joinPaths('a', 'b')).toEqual('a/b');
30-
expect(joinPaths('a', '/b')).toEqual('a/b');
31-
expect(joinPaths('/a', '/b')).toEqual('/a/b');
32-
expect(joinPaths('/a', '/b')).toEqual('/a/b');
33-
expect(joinPaths('/a/', '/b')).toEqual('/a/b');
34-
expect(joinPaths('/a', '/b/')).toEqual('/a/b/');
35-
expect(joinPaths('/a/', '/b/')).toEqual('/a/b/');
36-
37-
expect(joinPaths('', '', '')).toEqual('');
38-
expect(joinPaths('', 'b', '')).toEqual('b');
39-
expect(joinPaths('', 'b', 'c')).toEqual('b/c');
40-
expect(joinPaths('', '', 'c')).toEqual('c');
41-
expect(joinPaths('', '/b', '/c')).toEqual('/b/c');
42-
expect(joinPaths('/a', '', '/c')).toEqual('/a/c');
43-
expect(joinPaths('/a', '/b', '')).toEqual('/a/b');
44-
45-
expect(joinPaths('', '/')).toEqual('/');
46-
expect(joinPaths('a', '/')).toEqual('a/');
47-
expect(joinPaths('', '/', '/')).toEqual('/');
48-
expect(joinPaths('/', '/')).toEqual('/');
49-
expect(joinPaths('/', '')).toEqual('/');
50-
expect(joinPaths('/', 'b')).toEqual('/b');
51-
expect(joinPaths('/', 'b/')).toEqual('/b/');
52-
expect(joinPaths('/', '', '/')).toEqual('/');
53-
expect(joinPaths('/', 'b', '/')).toEqual('/b/');
54-
expect(joinPaths('/', 'b/', '/')).toEqual('/b/');
55-
expect(joinPaths('a', '/', '/')).toEqual('a/');
56-
expect(joinPaths('/', '/', 'c')).toEqual('/c');
57-
expect(joinPaths('/', '/', 'c/')).toEqual('/c/');
58-
});
59-
6021
test('isObject', () => {
6122
expect(isObject({})).toBeTruthy();
6223
expect(isObject([])).toBeFalsy();

0 commit comments

Comments
 (0)