File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ describe('getSourcedUris', () => {
11
11
expect ( result ) . toEqual ( new Set ( [ ] ) )
12
12
} )
13
13
14
- it ( 'returns an empty set if no files were sourced ' , ( ) => {
14
+ it ( 'returns a set of sourced files' , ( ) => {
15
15
const result = getSourcedUris ( {
16
16
fileContent : `
17
17
@@ -26,6 +26,13 @@ describe('getSourcedUris', () => {
26
26
source ~/myscript
27
27
28
28
# source ...
29
+
30
+ source "./my_quoted_file.sh"
31
+
32
+ source "$LIBPATH" # dynamic imports not supported
33
+
34
+ # conditional is currently not supported
35
+ if [[ -z $__COMPLETION_LIB_LOADED ]]; then source "$LIBPATH" ; fi
29
36
` ,
30
37
fileUri,
31
38
} )
@@ -36,6 +43,7 @@ describe('getSourcedUris', () => {
36
43
`${ fileDirectory } /x` ,
37
44
`${ fileDirectory } /relative/to-this.sh` ,
38
45
`${ homedir ( ) } /myscript` ,
46
+ `${ fileDirectory } /my_quoted_file.sh` ,
39
47
] ) ,
40
48
)
41
49
} )
Original file line number Diff line number Diff line change @@ -72,6 +72,17 @@ export function getSourcedLocation({
72
72
73
73
const mapPathToUri = ( path : string ) : string => path . replace ( 'file:' , 'file://' )
74
74
75
+ const stripQuotes = ( path : string ) : string => {
76
+ const first = path [ 0 ]
77
+ const last = path [ path . length - 1 ]
78
+
79
+ if ( first === last && [ `"` , `'` ] . includes ( first ) ) {
80
+ return path . slice ( 1 , - 1 )
81
+ }
82
+
83
+ return path
84
+ }
85
+
75
86
const getSourcedUri = ( {
76
87
relativePath,
77
88
uri,
@@ -83,10 +94,15 @@ const getSourcedUri = ({
83
94
// - we could try to resolve the path
84
95
// - "If filename does not contain a slash, file names in PATH are used to find
85
96
// the directory containing filename." (see https://ss64.com/osx/source.html)
97
+ const unquotedRelativePath = stripQuotes ( relativePath )
98
+
99
+ if ( unquotedRelativePath . includes ( '$' ) ) {
100
+ return null
101
+ }
86
102
87
- const resultPath = relativePath . startsWith ( '~' )
88
- ? untildify ( relativePath )
89
- : path . join ( path . dirname ( uri ) , relativePath )
103
+ const resultPath = unquotedRelativePath . startsWith ( '~' )
104
+ ? untildify ( unquotedRelativePath )
105
+ : path . join ( path . dirname ( uri ) , unquotedRelativePath )
90
106
91
107
return mapPathToUri ( resultPath )
92
108
}
You can’t perform that action at this time.
0 commit comments