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', () => {
35
35
expect ( variantInSection . toPathInSpace ( 'some/path/' ) ) . toBe ( '/section/variant/some/path' ) ;
36
36
} ) ;
37
37
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 ( '/' ) ;
40
41
expect ( variantInSection . toPathInSpace ( '' ) ) . toBe ( '/section/variant' ) ;
41
42
} ) ;
42
43
} ) ;
@@ -52,8 +53,9 @@ describe('toPathInSite', () => {
52
53
expect ( siteGitBookIO . toPathInSite ( 'some/path/' ) ) . toBe ( '/sitename/some/path' ) ;
53
54
} ) ;
54
55
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 ( '/' ) ;
57
59
expect ( siteGitBookIO . toPathInSite ( '' ) ) . toBe ( '/sitename' ) ;
58
60
} ) ;
59
61
} ) ;
Original file line number Diff line number Diff line change @@ -128,7 +128,8 @@ export function createLinker(
128
128
function joinPaths ( prefix : string , path : string ) : string {
129
129
const prefixPath = prefix . endsWith ( '/' ) ? prefix : `${ prefix } /` ;
130
130
const suffixPath = path . startsWith ( '/' ) ? path . slice ( 1 ) : path ;
131
- return removeTrailingSlash ( prefixPath + suffixPath ) ;
131
+ const pathWithoutTrailingSlash = removeTrailingSlash ( prefixPath + suffixPath ) ;
132
+ return pathWithoutTrailingSlash === '' ? '/' : pathWithoutTrailingSlash ;
132
133
}
133
134
134
135
function removeTrailingSlash ( path : string ) : string {
You can’t perform that action at this time.
0 commit comments