From 10a51ad996482d07ecfe4bcd3251b4e8701a30df Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 16 Sep 2024 00:15:54 -0400 Subject: [PATCH] Bugfix for string escaping in printouts --- parse.c | 2 +- stdlib/text.c | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/parse.c b/parse.c index 6f1d4b1..7e86d31 100644 --- a/parse.c +++ b/parse.c @@ -1276,7 +1276,7 @@ PARSER(parse_text) { ++pos; close_quote = closing[(int)open_quote] ? closing[(int)open_quote] : open_quote; - if (!lang && open_quote == '/') + if (!lang && (open_quote == '/' || open_quote == '|')) lang = "Pattern"; else if (!lang && open_quote == '(') lang = "Shell"; diff --git a/stdlib/text.c b/stdlib/text.c index ec54a5d..fd54204 100644 --- a/stdlib/text.c +++ b/stdlib/text.c @@ -1045,13 +1045,23 @@ static inline Text_t _quoted(Text_t text, bool colorize, char quote_char) case '\t': add_escaped("t"); break; case '\v': add_escaped("v"); break; case '\\': { - if (just_escaped) + if (just_escaped) { add_escaped("\\"); - else + } else { add_char('\\'); + just_escaped = false; + } + break; + } + case '$': { + if (quote_char == '\'') { + add_char('$'); + just_escaped = false; + } else { + add_escaped("$"); + } break; } - case '$': if (quote_char == '\'') add_char('$'); else add_escaped("$"); break; case '\x00' ... '\x06': case '\x0E' ... '\x1A': case '\x1C' ... '\x1F': case '\x7F' ... '\x7F': { if (colorize) add_str("\x1b[34;1m"); @@ -1062,13 +1072,16 @@ static inline Text_t _quoted(Text_t text, bool colorize, char quote_char) add_str(tmp); if (colorize) add_str("\x1b[0;35m"); + just_escaped = true; break; } default: { - if (g == quote_char) + if (g == quote_char) { add_escaped(((char[2]){quote_char, 0})); - else + } else { add_char(g); + just_escaped = false; + } break; } }