Skip to content

Commit

Permalink
add file existence check before reading extension
Browse files Browse the repository at this point in the history
  • Loading branch information
lucieleblanc committed Sep 6, 2024
1 parent ea10f6b commit 441c1c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ mod windows {

impl IsExecutable for Path {
fn is_executable(&self) -> bool {
// First, ensure that the file exists
if !self.is_file() {
return false;
}

// Check using file extension
if let Some(pathext) = std::env::var_os("PATHEXT") {
if let Some(extension) = self.extension() {
Expand Down
5 changes: 5 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ mod windows {
assert!(is_executable("./tests/i_am_executable_on_windows.bat"));
}

#[test]
fn non_existent_correct_extension() {
assert!(!is_executable("./tests/non_existent.exe"));
}

}

#[test]
Expand Down

0 comments on commit 441c1c7

Please sign in to comment.