Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove joinPaths function #26833

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions web_src/js/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {joinPaths} from './utils.js';

// DO NOT IMPORT window.config HERE!
// to make sure the error handler always works, we should never import `window.config`, because some user's custom template breaks it.

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

export function showGlobalErrorMessage(msg) {
const pageContent = document.querySelector('.page-content');
Expand Down
10 changes: 0 additions & 10 deletions web_src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ export function extname(path = '') {
return ext || '';
}

// join a list of path segments with slashes, ensuring no double slashes
export function joinPaths(...parts) {
let str = '';
for (const part of parts) {
if (!part) continue;
str = !str ? part : `${str.replace(/\/$/, '')}/${part.replace(/^\//, '')}`;
}
return str;
}

// test whether a variable is an object
export function isObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
Expand Down
41 changes: 1 addition & 40 deletions web_src/js/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, test} from 'vitest';
import {
basename, extname, isObject, stripTags, joinPaths, parseIssueHref,
basename, extname, isObject, stripTags, parseIssueHref,
parseUrl, translateMonth, translateDay, blobToDataURI,
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64,
} from './utils.js';
Expand All @@ -18,45 +18,6 @@ test('extname', () => {
expect(extname('file.js')).toEqual('.js');
});

test('joinPaths', () => {
expect(joinPaths('', '')).toEqual('');
expect(joinPaths('', 'b')).toEqual('b');
expect(joinPaths('', '/b')).toEqual('/b');
expect(joinPaths('', '/b/')).toEqual('/b/');
expect(joinPaths('a', '')).toEqual('a');
expect(joinPaths('/a', '')).toEqual('/a');
expect(joinPaths('/a/', '')).toEqual('/a/');
expect(joinPaths('a', 'b')).toEqual('a/b');
expect(joinPaths('a', '/b')).toEqual('a/b');
expect(joinPaths('/a', '/b')).toEqual('/a/b');
expect(joinPaths('/a', '/b')).toEqual('/a/b');
expect(joinPaths('/a/', '/b')).toEqual('/a/b');
expect(joinPaths('/a', '/b/')).toEqual('/a/b/');
expect(joinPaths('/a/', '/b/')).toEqual('/a/b/');

expect(joinPaths('', '', '')).toEqual('');
expect(joinPaths('', 'b', '')).toEqual('b');
expect(joinPaths('', 'b', 'c')).toEqual('b/c');
expect(joinPaths('', '', 'c')).toEqual('c');
expect(joinPaths('', '/b', '/c')).toEqual('/b/c');
expect(joinPaths('/a', '', '/c')).toEqual('/a/c');
expect(joinPaths('/a', '/b', '')).toEqual('/a/b');

expect(joinPaths('', '/')).toEqual('/');
expect(joinPaths('a', '/')).toEqual('a/');
expect(joinPaths('', '/', '/')).toEqual('/');
expect(joinPaths('/', '/')).toEqual('/');
expect(joinPaths('/', '')).toEqual('/');
expect(joinPaths('/', 'b')).toEqual('/b');
expect(joinPaths('/', 'b/')).toEqual('/b/');
expect(joinPaths('/', '', '/')).toEqual('/');
expect(joinPaths('/', 'b', '/')).toEqual('/b/');
expect(joinPaths('/', 'b/', '/')).toEqual('/b/');
expect(joinPaths('a', '/', '/')).toEqual('a/');
expect(joinPaths('/', '/', 'c')).toEqual('/c');
expect(joinPaths('/', '/', 'c/')).toEqual('/c/');
});

test('isObject', () => {
expect(isObject({})).toBeTruthy();
expect(isObject([])).toBeFalsy();
Expand Down