@ 261104.1

260915.1 · 24198d904a074f2943b2a3be925e53134c994734

fix: Better sanitizing

This refactors the sanitization code somewhat, to provide a couple benefits:

- Ensure we sanitize output in error messages (#2119), while not
escaping newlines from error messages.
- Avoids some unnecessary allocations and string copies
- Makes `print_error` a little nicer to use. As a macro, it avoids
needing a separate call to `format!`.

The main downside is added complexity.

Fixes: #2119

reading declarations

Changes to src/exec/job.rs. All files

src/exec/job.rs

@@ -1,5 +1,4 @@ use crate::config::Config;-use crate::error::print_error; use crate::exit_codes::{ExitCode, merge_exitcodes}; use crate::walk::WorkerResult; @@ -24,7 +23,7 @@ pub fn job(             WorkerResult::Entry(dir_entry) => dir_entry,             WorkerResult::Error(err) => {                 if config.show_filesystem_errors {-                    print_error(err.to_string());+                    print_error!("{}", err);                 }                 continue;             }@@ -54,7 +53,7 @@ pub fn batch(             WorkerResult::Entry(dir_entry) => Some(dir_entry.into_stripped_path(config)),             WorkerResult::Error(err) => {                 if config.show_filesystem_errors {-                    print_error(err.to_string());+                    print_error!("{}", err);                 }                 None             }