@@ -406,15 +406,15 @@ func (ctx *BuildContext) buildModule(analyzeMode bool) (meta *BuildMeta, include
406
406
return esbuild.OnResolveResult {Path : path }, nil
407
407
}
408
408
409
- // ban file: imports
410
- if strings .HasPrefix (args .Path , "file:" ) {
409
+ // ban ` file:` imports
410
+ if after , ok := strings .CutPrefix (args .Path , "file:" ); ok {
411
411
return esbuild.OnResolveResult {
412
- Path : fmt .Sprintf ("/error.js?type=unsupported-file-dependency&name=%s&importer=%s" , strings . TrimPrefix ( args . Path , "file:" ) , ctx .esmPath .Specifier ()),
412
+ Path : fmt .Sprintf ("/error.js?type=unsupported-file-dependency&name=%s&importer=%s" , after , ctx .esmPath .Specifier ()),
413
413
External : true ,
414
414
}, nil
415
415
}
416
416
417
- // skip data: and http: imports
417
+ // skip ` data:` and ` http:` imports
418
418
if strings .HasPrefix (args .Path , "data:" ) || strings .HasPrefix (args .Path , "https:" ) || strings .HasPrefix (args .Path , "http:" ) {
419
419
return esbuild.OnResolveResult {
420
420
Path : args .Path ,
@@ -546,6 +546,11 @@ func (ctx *BuildContext) buildModule(analyzeMode bool) (meta *BuildMeta, include
546
546
filename = path .Join (ctx .wd , "node_modules" , specifier )
547
547
}
548
548
549
+ // check if the filename is within the working directory
550
+ if ! strings .HasPrefix (filename , ctx .wd + string (os .PathSeparator )) {
551
+ return esbuild.OnResolveResult {}, fmt .Errorf ("could not resolve module %s" , specifier )
552
+ }
553
+
549
554
// node native modules do not work via http import
550
555
if strings .HasSuffix (filename , ".node" ) && existsFile (filename ) {
551
556
return esbuild.OnResolveResult {
0 commit comments