improve patch
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by curious-rabbit · committed by curious-rabbit · parent c96398c · Browse files · 3 files·+20 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+20 added−19 removed
- tests:+1 added−1 removed
- other:+19 added−18 removed
Provenance
- Commit
7d18db2- Tree
432ae80- Author
curious-rabbit <curious-rabbit@local>- Committer
curious-rabbit <curious-rabbit@local>- Parent
c96398c
3 files changed+20 added−19 removed
modified:src/exec/mod.rs+13 added-12 removed
41 unmodified lines42 Ok(CommandSet {43 mode: ExecutionMode::OneByOne,44 commands: input45 .into_iter()46- .map(CommandTemplate::new)46+ .map(|args| CommandTemplate::new(args, ExecutionMode::OneByOne))47 .collect::<Result<_>>()?,48 })49 }50 7 unmodified lines58 mode: ExecutionMode::Batch,59 commands: input60 .into_iter()61 .map(|args| {62- let cmd = CommandTemplate::new(args)?;62+ let cmd = CommandTemplate::new(args, ExecutionMode::Batch)?;63 if cmd.number_of_tokens() > 1 {64 bail!("Only one placeholder allowed for batch commands");65 }66 Ok(cmd)149 unmodified lines216 args: Vec<FormatTemplate>,217 }218 219 impl CommandTemplate {220- fn new<I, S>(input: I) -> Result<CommandTemplate>220+ fn new<I, S>(input: I, mode: ExecutionMode) -> Result<CommandTemplate>221 where222 I: IntoIterator<Item = S>,223 S: AsRef<str>,224 {16 unmodified lines241 if args.is_empty() {242 bail!("No executable provided for --exec or --exec-batch");243 }244 245- // Reject placeholder-as-executable for both --exec and --exec-batch246- // (was previously checked only for --exec-batch).247- if args[0].has_tokens() {245+ // A placeholder as the executable is meaningful for `--exec` but never for `--exec-batch`.246+ if mode == ExecutionMode::Batch && args[0].has_tokens() {247 bail!(249- "First argument of --exec/--exec-batch must be a fixed executable, not a placeholder"248+ "First argument of --exec-batch must be a fixed executable, not a placeholder"249 );250 }251 252 // If a placeholder token was not supplied, append one at the end of the command.115 unmodified lines368 }369 370 #[test]371 fn tokens_with_literal_braces() {373- let template = CommandTemplate::new(vec!["{{}}", "{{", "{.}}"]).unwrap();372+ let template =373+ CommandTemplate::new(vec!["{{}}", "{{", "{.}}"], ExecutionMode::OneByOne).unwrap();374 assert_eq!(375 generate_str(&template, "foo"),376 vec!["{}", "{", "{.}", "foo"]377 );378 }379 380 #[test]381 fn tokens_with_literal_braces_and_placeholder() {382- let template = CommandTemplate::new(vec!["echo", "{{{},end}"]).unwrap();382+ let template =383+ CommandTemplate::new(vec!["echo", "{{{},end}"], ExecutionMode::OneByOne).unwrap();384 assert_eq!(generate_str(&template, "foo"), vec!["echo", "{foo,end}"]);385 }386 387 #[test]38 unmodified lines426 }427 428 #[test]429 fn template_no_args() {429- assert!(CommandTemplate::new::<Vec<_>, &'static str>(vec![]).is_err());430+ assert!(CommandTemplate::new::<Vec<_>, &'static str>(vec![], ExecutionMode::OneByOne).is_err());431 }432 433 #[test]434 fn command_set_no_args() {1 unmodified line436 }437 438 #[test]439 fn placeholder_as_executable_rejected() {439- assert!(CommandSet::new(vec![vec!["{}"]]).is_err());440- assert!(CommandSet::new(vec![vec!["{/}", "arg"]]).is_err());440+ assert!(CommandSet::new(vec![vec!["{}"]]).is_ok());441+ assert!(CommandSet::new(vec![vec!["{/}", "arg"]]).is_ok());442 assert!(CommandSet::new_batch(vec![vec!["{}"]]).is_err());443 }444 445 #[test]41 unmodified linesmodified:tests/tests.rs+1 added-1 removed
1904 unmodified lines1905 );1906 1907 te.assert_failure_with_error(1908 &["foo", "--exec-batch", "echo {}"],1909- "error: First argument of --exec/--exec-batch must be a fixed executable, not a placeholder\n\1909+ "error: First argument of --exec-batch must be a fixed executable, not a placeholder\n\1910 \n\1911 Usage: fd [OPTIONS] [pattern] [path]...\n\1912 \n\1913 For more information, try '--help'.\n\847 unmodified linesmodified:CHANGELOG.md+6 added-6 removed
1 # Unreleased2 3+## Features4+- Add `--ignore-parent` option to override `--no-ignore-parent`, see #1958 (@tmchow)5+6 ## Bugfixes7 - Sanitize control characters and bidirectional override characters in filenames5- when output goes to a terminal, and prefix paths starting with `-` with `./` to6- prevent argument injection. Also reject placeholders as the executable in7- `--exec`/`--exec-batch` (was previously checked only for `--exec-batch`).8+ when output goes to a terminal, to prevent terminal escape-sequence injection.9+ Also reject a placeholder as the executable for `--exec-batch`, while still10+ allowing it for `--exec`.11 - Handle invalid working directories gracefully when using `--full-path`, see #1900 (@Xavrir).12 10-## Features11-- Add `--ignore-parent` option to override `--no-ignore-parent`, see #1958 (@tmchow)12-13 # 10.4.214 15 ## Bugfixes16 - Fixed performance regression due to `--ignore-contain`; see #1913 and #1914845 unmodified lines