File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
dev-packages/node-integration-tests/suites/contextLines Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ describe('ContextLines integration', () => {
2525 lineno : 3 ,
2626 function : '?' ,
2727 in_app : true ,
28- module : 'scenario%20with%20space ' ,
28+ module : 'scenario with space ' ,
2929 } ,
3030 ] ) ,
3131 } ,
Original file line number Diff line number Diff line change @@ -29,23 +29,27 @@ export function createGetModuleFromFilename(
2929 file = file . slice ( 0 , ext . length * - 1 ) ;
3030 }
3131
32+ // The file name might be URI-encoded which we want to decode to
33+ // the original file name.
34+ const decodedFile = decodeURIComponent ( file ) ;
35+
3236 if ( ! dir ) {
3337 // No dirname whatsoever
3438 dir = '.' ;
3539 }
3640
3741 const n = dir . lastIndexOf ( '/node_modules' ) ;
3842 if ( n > - 1 ) {
39- return `${ dir . slice ( n + 14 ) . replace ( / \/ / g, '.' ) } :${ file } ` ;
43+ return `${ dir . slice ( n + 14 ) . replace ( / \/ / g, '.' ) } :${ decodedFile } ` ;
4044 }
4145
4246 // Let's see if it's a part of the main module
4347 // To be a part of main module, it has to share the same base
4448 if ( dir . startsWith ( normalizedBase ) ) {
4549 const moduleName = dir . slice ( normalizedBase . length + 1 ) . replace ( / \/ / g, '.' ) ;
46- return moduleName ? `${ moduleName } :${ file } ` : file ;
50+ return moduleName ? `${ moduleName } :${ decodedFile } ` : decodedFile ;
4751 }
4852
49- return file ;
53+ return decodedFile ;
5054 } ;
5155}
Original file line number Diff line number Diff line change @@ -16,6 +16,11 @@ describe('createGetModuleFromFilename', () => {
1616 expect ( getModule ( '/path/to/base/file.js' ) ) . toBe ( 'file' ) ;
1717 } ) ;
1818
19+ it ( 'decodes URI-encoded file names' , ( ) => {
20+ const getModule = createGetModuleFromFilename ( ) ;
21+ expect ( getModule ( '/path%20with%space/file%20with%20spaces(1).js' ) ) . toBe ( 'file with spaces(1)' ) ;
22+ } ) ;
23+
1924 it ( 'returns undefined if no filename is provided' , ( ) => {
2025 const getModule = createGetModuleFromFilename ( ) ;
2126 expect ( getModule ( undefined ) ) . toBeUndefined ( ) ;
@@ -29,7 +34,7 @@ describe('createGetModuleFromFilename', () => {
2934 expect ( getModule ( filename ) ) . toBe ( expected ) ;
3035 } ) ;
3136
32- it ( 'handles windows paths with passed basePath' , ( ) => {
37+ it ( 'handles windows paths with passed basePath and node_modules ' , ( ) => {
3338 const getModule = createGetModuleFromFilename ( 'C:\\path\\to\\base' , true ) ;
3439 expect ( getModule ( 'C:\\path\\to\\base\\node_modules\\somePkg\\file.js' ) ) . toBe ( 'somePkg:file' ) ;
3540 } ) ;
You can’t perform that action at this time.
0 commit comments