diff --git a/src/routes.ts b/src/routes.ts index acd87cf1c9..2dcee0832c 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -86,7 +86,7 @@ export function createHref( const compiledRoute = `${compile(preparedRoute)(params)}${search}`; - if (options.withBasename) { + if (options.withBasename && basename) { // For SPA links react-router adds basename itself // It is needed for external links - or uikit return normalizePathSlashes(`${basename}/${compiledRoute}`); diff --git a/src/utils/__test__/index.test.ts b/src/utils/__test__/index.test.ts index 7fb6a0ce40..68ee8371e2 100644 --- a/src/utils/__test__/index.test.ts +++ b/src/utils/__test__/index.test.ts @@ -16,6 +16,9 @@ describe('normalizePathSlashes', () => { test('should handle paths with multiple trailing slashes', () => { expect(normalizePathSlashes('path////')).toBe('path/'); }); + test('should handle paths with multiple leading slashes', () => { + expect(normalizePathSlashes('////path')).toBe('/path'); + }); test('should handle full paths with normal slashes', () => { expect(normalizePathSlashes('http://example.com/path/to/resource')).toBe( 'http://example.com/path/to/resource', @@ -26,9 +29,14 @@ describe('normalizePathSlashes', () => { 'http://example.com/path/to/resource', ); }); + test('should not replace double slashes near protocols (after a colon)', () => { + expect(normalizePathSlashes('http://host.ydb.com')).toBe('http://host.ydb.com'); + expect(normalizePathSlashes('https://host.ydb.com')).toBe('https://host.ydb.com'); + expect(normalizePathSlashes('grpc://host.ydb.com')).toBe('grpc://host.ydb.com'); + }); test('should replace slashes more than two slashes after a colon', () => { - expect(normalizePathSlashes('http://///example.com/path/to/resource')).toBe( - 'http://example.com/path/to/resource', - ); + expect(normalizePathSlashes('http:////host.ydb.com')).toBe('http://host.ydb.com'); + expect(normalizePathSlashes('https://///host.ydb.com')).toBe('https://host.ydb.com'); + expect(normalizePathSlashes('grpc://///host.ydb.com')).toBe('grpc://host.ydb.com'); }); }); diff --git a/src/utils/index.ts b/src/utils/index.ts index 12eb24a548..8de8c148cc 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -14,5 +14,6 @@ export async function wait(time: number, value?: T): Promise