File tree Expand file tree Collapse file tree 2 files changed +46
-7
lines changed Expand file tree Collapse file tree 2 files changed +46
-7
lines changed Original file line number Diff line number Diff line change 11import {
2+ cleanPath ,
23 getPath ,
34 isAbsolutePath ,
4- stringifyQuery ,
5- cleanPath ,
65 replaceSlug ,
76 resolvePath ,
7+ stringifyQuery ,
88} from '../util.js' ;
99import { noop } from '../../util/core.js' ;
1010
@@ -32,11 +32,19 @@ export class History {
3232 }
3333
3434 #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 ;
4048 }
4149
4250 getBasePath ( ) {
Original file line number Diff line number Diff line change @@ -66,4 +66,35 @@ describe('router/history/base', () => {
6666 expect ( url ) . toBe ( '/README' ) ;
6767 } ) ;
6868 } ) ;
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+ } ) ;
69100} ) ;
You can’t perform that action at this time.
0 commit comments