Repository navigation
chore: clean up module path handling from local - #6086
Conversation
3a31631 to
ead9476
Compare
There was a problem hiding this comment.
This is actually the main "change" of this PR.
It ensures that a dependency "../foo" can't be loaded if the root is ".". Previously, this would silently succeed, and maybe actually try and load "./foo" instead.
However, we should explicitly error out.
There was a problem hiding this comment.
nit: any assertion on actual error (even just checking for a string) would be highly preferable so we have less chance of ending up in a situation where the test starts failing in the future but for a different reason and then we silently lose coverage
There was a problem hiding this comment.
Updated to do this 🎉
Also bumped some things to handle the bad-self-dir where we should perform the filepath.Rel checks on absolute paths there so we don't get the weird Rel errors, and instead get our custom errors.
This patch detects some additional edge cases when loading modules, notably: - Fail if the server tries to load a module where the config is not under the root - this is still also checked client-side for the main module. However, by adding checks server-side, we also get this for dependencies as well. Additionally, a few small nitpicks: - Use `path/filepath` instead of `path`. `path/filepath` uses OS-depedendant separators, which, while we're not using this, highlights that these are files. - Use filepath utilities wherever possible (e.g. use `filepath.Rel` instead of `strings.TrimPrefix`). - Check if a path is a parent to the current directory - `strings.HasPrefix(target, "..")` wasn't right, since a normal filename *can* begin with `..`. Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
ead9476 to
216abfd
Compare
Signed-off-by: Christian Schlatter <[email protected]>
This patch detects some additional edge cases when loading modules, notably:
Additionally, a few small nitpicks:
Use
path/filepathinstead ofpath.path/filepathuses OS-depedendant separators, which, while we're not using this, highlights that these are files.Use filepath utilities wherever possible (e.g. use
filepath.Relinstead ofstrings.TrimPrefix).Check if a path is a parent to the current directory -
strings.HasPrefix(target, "..")wasn't right, since a normal filename can begin with...