File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed
packages/gitbook-v2/src/lib Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,9 @@ describe('toPathInSpace', () => {
3535 expect ( variantInSection . toPathInSpace ( 'some/path/' ) ) . toBe ( '/section/variant/some/path' ) ;
3636 } ) ;
3737
38- it ( 'should not add a trailing slash' , ( ) => {
39- expect ( root . toPathInSpace ( '' ) ) . toBe ( '' ) ;
38+ it ( 'should not add an unnecessary trailing slash' , ( ) => {
39+ // The index page should not be an empty path
40+ expect ( root . toPathInSpace ( '' ) ) . toBe ( '/' ) ;
4041 expect ( variantInSection . toPathInSpace ( '' ) ) . toBe ( '/section/variant' ) ;
4142 } ) ;
4243} ) ;
@@ -52,8 +53,9 @@ describe('toPathInSite', () => {
5253 expect ( siteGitBookIO . toPathInSite ( 'some/path/' ) ) . toBe ( '/sitename/some/path' ) ;
5354 } ) ;
5455
55- it ( 'should not add a trailing slash' , ( ) => {
56- expect ( root . toPathInSite ( '' ) ) . toBe ( '' ) ;
56+ it ( 'should not add an unnecessary trailing slash' , ( ) => {
57+ // The index page should not be an empty path
58+ expect ( root . toPathInSite ( '' ) ) . toBe ( '/' ) ;
5759 expect ( siteGitBookIO . toPathInSite ( '' ) ) . toBe ( '/sitename' ) ;
5860 } ) ;
5961} ) ;
Original file line number Diff line number Diff line change @@ -128,7 +128,8 @@ export function createLinker(
128128function joinPaths ( prefix : string , path : string ) : string {
129129 const prefixPath = prefix . endsWith ( '/' ) ? prefix : `${ prefix } /` ;
130130 const suffixPath = path . startsWith ( '/' ) ? path . slice ( 1 ) : path ;
131- return removeTrailingSlash ( prefixPath + suffixPath ) ;
131+ const pathWithoutTrailingSlash = removeTrailingSlash ( prefixPath + suffixPath ) ;
132+ return pathWithoutTrailingSlash === '' ? '/' : pathWithoutTrailingSlash ;
132133}
133134
134135function removeTrailingSlash ( path : string ) : string {
You can’t perform that action at this time.
0 commit comments