Skip to content

Commit

Permalink
Build: Fix exceptions (#10616)
Browse files Browse the repository at this point in the history
We were passing the path to the constructor,
but that argument is actually the message.

The message is already defined in the exception itself.

---------

Co-authored-by: Manuel Kaufmann <humitos@gmail.com>
  • Loading branch information
stsewd and humitos authored Aug 10, 2023
1 parent e11792b commit e766968
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions readthedocs/core/utils/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def safe_open(
)

if path.exists() and not path.is_file():
raise FileIsNotRegularFile(path)
raise FileIsNotRegularFile()

if not allow_symlinks and path.is_symlink():
log.info("Skipping file becuase it's a symlink.")
raise UnsupportedSymlinkFileError(path)
raise UnsupportedSymlinkFileError()

# Expand symlinks.
resolved_path = path.resolve()
Expand All @@ -89,17 +89,21 @@ def safe_open(
file_size = resolved_path.stat().st_size
if file_size > max_size_bytes:
log.info("File is too large.", size_bytes=file_size)
raise FileTooLarge(path)
raise FileTooLarge()

if allow_symlinks and base_path:
base_path = Path(base_path).absolute()
if not resolved_path.is_relative_to(base_path):
# Trying to path traversal via a symlink, sneaky!
log.info("Path traversal via symlink.")
raise SymlinkOutsideBasePath(path)
raise SymlinkOutsideBasePath()

_assert_path_is_inside_docroot(resolved_path)

# The encoding is valid only if the file opened is a text file,
# this function is used to read both types of files (text and binary),
# so we can't specify the encoding here.
# pylint: disable=unspecified-encoding
return resolved_path.open(*args, **kwargs)


Expand Down

0 comments on commit e766968

Please sign in to comment.