File tree 2 files changed +46
-7
lines changed
2 files changed +46
-7
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
+ cleanPath ,
2
3
getPath ,
3
4
isAbsolutePath ,
4
- stringifyQuery ,
5
- cleanPath ,
6
5
replaceSlug ,
7
6
resolvePath ,
7
+ stringifyQuery ,
8
8
} from '../util.js' ;
9
9
import { noop } from '../../util/core.js' ;
10
10
@@ -32,11 +32,19 @@ export class History {
32
32
}
33
33
34
34
#getFileName( path , ext ) {
35
- return new RegExp ( `\\.(${ ext . replace ( / ^ \. / , '' ) } |html)$` , 'g' ) . test ( path )
36
- ? path
37
- : / \/ $ / g. test ( path )
38
- ? `${ path } README${ ext } `
39
- : `${ path } ${ ext } ` ;
35
+ const [ basePath , query ] = path . split ( '?' ) ;
36
+
37
+ const hasValidExt = new RegExp ( `\\.(${ ext . replace ( / ^ \. / , '' ) } |html)$` ) . test (
38
+ basePath ,
39
+ ) ;
40
+
41
+ const updatedPath = hasValidExt
42
+ ? basePath
43
+ : / \/ $ / g. test ( basePath )
44
+ ? `${ basePath } README${ ext } `
45
+ : `${ basePath } ${ ext } ` ;
46
+
47
+ return query ? `${ updatedPath } ?${ query } ` : updatedPath ;
40
48
}
41
49
42
50
getBasePath ( ) {
Original file line number Diff line number Diff line change @@ -66,4 +66,35 @@ describe('router/history/base', () => {
66
66
expect ( url ) . toBe ( '/README' ) ;
67
67
} ) ;
68
68
} ) ;
69
+
70
+ // getFile test
71
+ // ---------------------------------------------------------------------------
72
+ describe ( 'getFile' , ( ) => {
73
+ // Tests
74
+ // -------------------------------------------------------------------------
75
+ test ( 'path is url' , ( ) => {
76
+ const file = history . getFile ( 'https://some/raw/url/README.md' ) ;
77
+
78
+ expect ( file ) . toBe ( 'https://some/raw/url/README.md' ) ;
79
+ } ) ;
80
+ test ( 'path is url, but ext is .html' , ( ) => {
81
+ const file = history . getFile ( 'https://foo.com/index.html' ) ;
82
+
83
+ expect ( file ) . toBe ( 'https://foo.com/index.html' ) ;
84
+ } ) ;
85
+ test ( 'path is url, but with parameters' , ( ) => {
86
+ const file = history . getFile (
87
+ 'https://some/raw/url/README.md?token=Mytoken' ,
88
+ ) ;
89
+
90
+ expect ( file ) . toBe ( 'https://some/raw/url/README.md?token=Mytoken' ) ;
91
+ } ) ;
92
+ test ( 'path is url, but ext is different' , ( ) => {
93
+ history = new MockHistory ( { ext : '.ext' } ) ;
94
+
95
+ const file = history . getFile ( 'https://some/raw/url/README.md' ) ;
96
+
97
+ expect ( file ) . toBe ( 'https://some/raw/url/README.md.ext' ) ;
98
+ } ) ;
99
+ } ) ;
69
100
} ) ;
You can’t perform that action at this time.
0 commit comments