Skip to content

Commit

Permalink
fix(core): prevent useBaseUrl returning /base/base when on /base (#6993)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena authored Mar 25, 2022
1 parent dc95cb8 commit e8800b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('useBaseUrl', () => {
expect(mockUseBaseUrl('/hello/foo', {absolute: true})).toBe(
'https://docusaurus.io/docusaurus/hello/foo',
);
expect(mockUseBaseUrl('/docusaurus')).toBe('/docusaurus/');
expect(mockUseBaseUrl('/docusaurus/')).toBe('/docusaurus/');
expect(mockUseBaseUrl('/docusaurus/hello')).toBe('/docusaurus/hello');
expect(mockUseBaseUrl('#hello')).toBe('#hello');
Expand Down Expand Up @@ -143,6 +144,7 @@ describe('useBaseUrlUtils().withBaseUrl()', () => {
expect(withBaseUrl('/hello/foo', {absolute: true})).toBe(
'https://docusaurus.io/docusaurus/hello/foo',
);
expect(withBaseUrl('/docusaurus')).toBe('/docusaurus/');
expect(withBaseUrl('/docusaurus/')).toBe('/docusaurus/');
expect(withBaseUrl('/docusaurus/hello')).toBe('/docusaurus/hello');
expect(withBaseUrl('#hello')).toBe('#hello');
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus/src/client/exports/useBaseUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function addBaseUrl(
return baseUrl + url.replace(/^\//, '');
}

// /baseUrl -> /baseUrl/
// https://github.com/facebook/docusaurus/issues/6315
if (url === baseUrl.replace(/\/$/, '')) {
return baseUrl;
}

// We should avoid adding the baseurl twice if it's already there
const shouldAddBaseUrl = !url.startsWith(baseUrl);

Expand Down

0 comments on commit e8800b9

Please sign in to comment.