From 529b6a61e222906475df346b212324511f9ac16d Mon Sep 17 00:00:00 2001 From: djairoh Date: Wed, 8 Feb 2023 22:09:18 +0100 Subject: [PATCH] enforced ASCII validation on '--map' flag --- src/ascii_manipulation.rs | 1 - src/cli.rs | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ascii_manipulation.rs b/src/ascii_manipulation.rs index 70887ea..7231966 100644 --- a/src/ascii_manipulation.rs +++ b/src/ascii_manipulation.rs @@ -17,7 +17,6 @@ fn to_ascii(char_map: String, image: DynamicImage) -> Vec> { for pixel in image.pixels() { let ch = char_map.as_bytes()[((get_color(pixel.2) as f32-1.0)/255f32 * l) as usize]; - //fixme: might break with non-ASCII char_map str.push(Ascii::new(ch, pixel.2[0], pixel.2[1], pixel.2[2])); if pixel.0 == image.width()-1 { diff --git a/src/cli.rs b/src/cli.rs index d8f2b6b..b541c29 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -92,6 +92,13 @@ impl Cli { exit(1); } } + + if let Some(map) = self.map.clone() { + if !map.is_ascii() { + error!("map can not contain non-ASCII characters!"); + exit(1); + } + } } pub fn init(&self) {