From cffb3726cc2d251bc145f8eac073505bf74269d1 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 22 Sep 2023 10:08:28 -0700 Subject: [PATCH] Character checks, minor cleanup --- src/lib.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ceed6cc..6917f51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,15 +68,12 @@ cfg_if::cfg_if! { return format!("\r\n{}", daisy_prompt(state)); } - if in_str.trim() == "quit" { - return "[quit]".to_string(); - } else { - let r = crate::do_string( unsafe { &mut (*state).context }, &in_str); - match r { - Ok(t) | Err(t) => { - out += t; - } + let r = crate::do_string( unsafe { &mut (*state).context }, &in_str); + + match r { + Ok(t) | Err(t) => { + out += t; } } }, @@ -91,7 +88,20 @@ cfg_if::cfg_if! { //'\x04' | '\x03' //=> { break 'outer; }, - _ => { unsafe { (*state).promptbuffer.add_char(s.chars().next().unwrap()); } }, + // Only process sane characters + + _ => { + let c = s.chars().next().unwrap(); + match c { + 'a'..='z' | 'A'..='Z' | '0'..='9' + |'!'|'@'|'#'|'$'|'%'|'^'|'&'|'*'|'('|')' + |'?'|'~'|','|'.'|'['|']' + |'<'|'>'|'/'|'_'|'-'|':'|'|'|'='|'+'|';' + => { unsafe { (*state).promptbuffer.add_char(c); } }, + + _ => {} + } + }, }; let t = unsafe { (*state).promptbuffer.write_prompt(&mut (*state).context) };