diff options
author | Adrian Rivera <adrian.rivera.dev@gmail.com> | 2020-10-25 02:13:57 -0700 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2020-10-29 19:33:58 +0100 |
commit | 9837948c3a7d59b0629ed5f176cd2861eb340af0 (patch) | |
tree | 9364e99d1b251d2aa9cf7f755efeeab9e8de8129 | |
parent | 072fb380d82df11e167d34b6a37dfe9fe1a2fb19 (diff) |
Throws an error when `bat` is being user as pager.
As mentioned on #1334 `bat` should not be used as a value for `pager`,
this change checks both the balue of `bat` provided as a parameter or
as an environment variable.
-rw-r--r-- | src/error.rs | 4 | ||||
-rw-r--r-- | src/output.rs | 4 | ||||
-rw-r--r-- | tests/integration_tests.rs | 10 |
3 files changed, 16 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs index 2e73b85b..3e5b3711 100644 --- a/src/error.rs +++ b/src/error.rs @@ -20,6 +20,10 @@ error_chain! { description("unknown syntax"), display("unknown syntax: '{}'", name) } + InvalidPagerValueBat { + description("invalid value `bat` for pager property"), + display("Use of bat as a pager is disallowed in order to avoid infinite recursion problems") + } } } diff --git a/src/output.rs b/src/output.rs index b0d5974e..689371b9 100644 --- a/src/output.rs +++ b/src/output.rs @@ -85,10 +85,10 @@ impl OutputType { match pagerflags.split_first() { Some((pager_name, args)) => { - let mut pager_path = PathBuf::from(pager_name); + let pager_path = PathBuf::from(pager_name); if pager_path.file_stem() == Some(&OsString::from("bat")) { - pager_path = PathBuf::from("less"); + return Err(ErrorKind::InvalidPagerValueBat.into()); } let is_less = pager_path.file_stem() == Some(&OsString::from("less")); diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index da0690ef..09ac8498 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -406,6 +406,16 @@ fn pager_disable() { } #[test] +fn pager_value_bat() { + bat() + .arg("--pager=bat") + .arg("--paging=always") + .arg("test.txt") + .assert() + .failure(); +} + +#[test] fn alias_pager_disable() { bat() .env("PAGER", "echo other-pager") |