From 7070e931a3c5c3070fa50d7d0e3c1918e89e1c78 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 8 Aug 2023 16:05:54 -0500 Subject: [PATCH 1/3] Build: Fix exceptions We were passing the path to the constructor, but that argument is actually the message. The message is already defined in the exception itself. --- readthedocs/core/utils/filesystem.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readthedocs/core/utils/filesystem.py b/readthedocs/core/utils/filesystem.py index 777b933471f..003950636ee 100644 --- a/readthedocs/core/utils/filesystem.py +++ b/readthedocs/core/utils/filesystem.py @@ -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() @@ -89,14 +89,14 @@ 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) From 124ddf99087f3a7be0707a004028b8d160bc23fc Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 8 Aug 2023 16:38:03 -0500 Subject: [PATCH 2/3] Linter --- readthedocs/core/utils/filesystem.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readthedocs/core/utils/filesystem.py b/readthedocs/core/utils/filesystem.py index 003950636ee..14d575a6d19 100644 --- a/readthedocs/core/utils/filesystem.py +++ b/readthedocs/core/utils/filesystem.py @@ -100,6 +100,10 @@ def safe_open( _assert_path_is_inside_docroot(resolved_path) + # The encoding is valid only if the file opened is a text file, + # this functions 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) From d081d4272fbb342384129aff190105f730744c93 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Wed, 9 Aug 2023 12:15:59 -0500 Subject: [PATCH 3/3] Update readthedocs/core/utils/filesystem.py Co-authored-by: Manuel Kaufmann --- readthedocs/core/utils/filesystem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs/core/utils/filesystem.py b/readthedocs/core/utils/filesystem.py index 14d575a6d19..6abff7cf842 100644 --- a/readthedocs/core/utils/filesystem.py +++ b/readthedocs/core/utils/filesystem.py @@ -101,7 +101,7 @@ def safe_open( _assert_path_is_inside_docroot(resolved_path) # The encoding is valid only if the file opened is a text file, - # this functions is used to read both types of files (text and binary), + # 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)