aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/degesch.c b/degesch.c
index 5d5108e..a6826d6 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2561,6 +2561,23 @@ formatter_flush_attr
}
static void
+formatter_flush_text (struct app_context *ctx, const char *text, FILE *stream)
+{
+ struct str sanitized;
+ str_init (&sanitized);
+
+ // Throw away any potentially harmful control characters
+ char *term = iconv_xstrdup (ctx->term_from_utf8, (char *) text, -1, NULL);
+ for (char *p = term; *p; p++)
+ if (!strchr ("\a\b\x1b", *p))
+ str_append_c (&sanitized, *p);
+ free (term);
+
+ fputs (sanitized.str, stream);
+ str_free (&sanitized);
+}
+
+static void
formatter_flush (struct formatter *self, FILE *stream)
{
terminal_printer_fn printer = get_attribute_printer (stream);
@@ -2579,23 +2596,13 @@ formatter_flush (struct formatter *self, FILE *stream)
int attribute_ignore = 0;
LIST_FOR_EACH (struct formatter_item, iter, self->items)
{
- switch (iter->type)
- {
- char *term;
- case FORMATTER_ITEM_TEXT:
- term = iconv_xstrdup
- (self->ctx->term_from_utf8, iter->text, -1, NULL);
- fputs (term, stream);
- free (term);
- break;
- case FORMATTER_ITEM_IGNORE_ATTR:
+ if (iter->type == FORMATTER_ITEM_TEXT)
+ formatter_flush_text (self->ctx, iter->text, stream);
+ else if (iter->type == FORMATTER_ITEM_IGNORE_ATTR)
attribute_ignore += iter->attribute;
- break;
- default:
- if (attribute_ignore <= 0
- && !formatter_flush_attr (&state, iter))
+ else if (attribute_ignore <= 0
+ && !formatter_flush_attr (&state, iter))
hard_assert (!"unhandled formatter item type");
- }
}
attribute_printer_reset (&state);
}