Skip to content

Commit

Permalink
Make initcontext's openImpl use fsext.Abs
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Nov 10, 2023
1 parent 9971f1e commit 3a16a29
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions js/initcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"net/url"
"path/filepath"

"github.com/dop251/goja"
"github.com/sirupsen/logrus"
Expand All @@ -20,20 +19,7 @@ const cantBeUsedOutsideInitContextMsg = `the "%s" function is only available in
// contents of a file. If the second argument is "b" it returns an ArrayBuffer
// instance, otherwise a string representation.
func openImpl(rt *goja.Runtime, fs fsext.Fs, basePWD *url.URL, filename string, args ...string) (goja.Value, error) {
// Here IsAbs should be enough but unfortunately it doesn't handle absolute paths starting from
// the current drive on windows like `\users\noname\...`. Also it makes it more easy to test and
// will probably be need for archive execution under windows if always consider '/...' as an
// absolute path.
if filename[0] != '/' && filename[0] != '\\' && !filepath.IsAbs(filename) {
filename = filepath.Join(basePWD.Path, filename)
}
filename = filepath.Clean(filename)

if filename[0:1] != fsext.FilePathSeparator {
filename = fsext.FilePathSeparator + filename
}

data, err := readFile(fs, filename)
data, err := readFile(fs, fsext.Abs(basePWD.Path, filename))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 3a16a29

Please sign in to comment.