From d45e7cf5a3f82cde5e931780bd4f4b4b9e4ef69b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 28 May 2021 19:02:01 -0500 Subject: [PATCH] fix(cli): Don't crash on stdin Fixes #264 --- CHANGELOG.md | 4 ++++ Cargo.lock | 24 ++++++++++++++++++++++++ Cargo.toml | 1 + src/file.rs | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0efa76855..a1fc87cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +#### Bug Fixes + +- Fix crash when processing stdin (`-`) + ## [1.0.2] - 2021-05-28 #### Bug Fixes diff --git a/Cargo.lock b/Cargo.lock index e0fc50a14..61e6368e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,20 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "assert_cmd" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f57fec1ac7e4de72dcc69811795f1a7172ed06012f80a5d1ee651b62484f588" +dependencies = [ + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "assert_fs" version = "1.0.2" @@ -1475,6 +1489,7 @@ version = "1.0.2" dependencies = [ "ahash", "anyhow", + "assert_cmd", "assert_fs", "atty", "bstr", @@ -1647,6 +1662,15 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + [[package]] name = "walkdir" version = "2.3.2" diff --git a/Cargo.toml b/Cargo.toml index 98bc433ca..2e36fa581 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,6 +83,7 @@ typed-arena = "2.0.1" [dev-dependencies] assert_fs = "1.0" +assert_cmd = "1.0" predicates = "1.0" criterion = "0.3" maplit = "1.0" diff --git a/src/file.rs b/src/file.rs index 54157f997..ba482c660 100644 --- a/src/file.rs +++ b/src/file.rs @@ -600,7 +600,7 @@ fn walk_entry( let explicit = entry.depth() == 0; let (path, lookup_path) = if entry.is_stdin() { let path = std::path::Path::new("-"); - (path, path.to_owned()) + (path, std::env::current_dir()?) } else { let path = entry.path(); (path, path.canonicalize()?)