Skip to content

Commit

Permalink
fix that relatives paths could break out of current directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sandbubbles committed Oct 5, 2024
1 parent b1dee66 commit bc7d569
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions vyper/compiler/input_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ def _generate_source_id(self, resolved_path: PathLike) -> int:

return self._source_ids[resolved_path]

def load_file(self, path: PathLike | str) -> CompilerInput:
def load_file(self, path: PathLike | str, level: int = 0) -> CompilerInput:
# search path precedence
tried = []
search_paths = self.search_paths if level == 0 else [self.search_paths[-1]]

if isinstance(path, str):
path = PurePath(path)
for sp in reversed(self.search_paths):
for sp in reversed(search_paths):
# note from pathlib docs:
# > If the argument is an absolute path, the previous path is ignored.
# Path("/a") / Path("/b") => Path("/b")
Expand Down
6 changes: 3 additions & 3 deletions vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ def _load_import_helper(

try:
path_vy = path.with_suffix(".vy")
file = self.input_bundle.load_file(path_vy)
file = self.input_bundle.load_file(path_vy, level)
assert isinstance(file, FileInput) # mypy hint

module_ast = self._ast_from_file(file)
Expand All @@ -838,7 +838,7 @@ def _load_import_helper(
err = e

try:
file = self.input_bundle.load_file(path.with_suffix(".vyi"))
file = self.input_bundle.load_file(path.with_suffix(".vyi"), level)
assert isinstance(file, FileInput) # mypy hint
module_ast = self._ast_from_file(file)

Expand All @@ -857,7 +857,7 @@ def _load_import_helper(
pass

try:
file = self.input_bundle.load_file(path.with_suffix(".json"))
file = self.input_bundle.load_file(path.with_suffix(".json"), level)
assert isinstance(file, ABIInput) # mypy hint
return file, InterfaceT.from_json_abi(str(file.path), file.abi)
except FileNotFoundError:
Expand Down

0 comments on commit bc7d569

Please sign in to comment.