From a5c4f5d3163a84c0a019fd9dc662f6e49a89818b Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Fri, 1 Sep 2023 09:29:33 +0200 Subject: colorize: handle spaces in styleset Avoid failure when the styleset [viewer] section contains spaces: ~$ cat foo [viewer] url.fg = #ffffaf url.underline = true header.fg = #af87ff signature.fg = #af87ff diff_meta.fg = #ffffff diff_meta.bold = true diff_chunk.fg = #00cdcd diff_add.fg = #00cd00 diff_del.fg = #cd0000 quote_1.fg = #5fafff quote_2.fg = #ff8700 quote_3.fg = #af87ff quote_4.fg = #ff5fd7 quote_x.fg = #808080 ~$ ./colorize -s foo < bar.eml error: invalid style attribute 'fg ' Be more restrictive with what characters are part of a style attribute. Add test styleset with as much weirdness as possible. Update vectors accordingly. Update sendemail-validate hook to export pedantic CFLAGS. Reported-by: Tristan Partin Signed-off-by: Robin Jarry Reviewed-by: Tristan Partin Tested-by: Tristan Partin --- filters/colorize.c | 13 +++-- filters/test.sh | 25 ++++++++++ filters/vectors/colorize-patch.expected | 62 ++++++++++++------------ filters/vectors/colorize-quotes.expected | 82 ++++++++++++++++---------------- 4 files changed, 105 insertions(+), 77 deletions(-) (limited to 'filters') diff --git a/filters/colorize.c b/filters/colorize.c index b00a88c4..d991cb72 100644 --- a/filters/colorize.c +++ b/filters/colorize.c @@ -257,7 +257,7 @@ static int parse_color(struct color *c, const char *val) c->type = RGB; c->rgb = color; } else { - fprintf(stderr, "error: invalid color value %s\n", val); + fprintf(stderr, "error: invalid color value '%s'\n", val); return 1; } return 0; @@ -272,7 +272,7 @@ static int parse_bool(bool *b, const char *val) } else if (!strcmp(val, "toggle")) { *b = !*b; } else { - fprintf(stderr, "error: invalid bool value %s\n", val); + fprintf(stderr, "error: invalid bool value '%s'\n", val); return 1; } return 0; @@ -314,7 +314,7 @@ static int set_attr(struct style *s, const char *attr, const char *val) s->fg.type = NONE; s->fg.type = NONE; } else { - fprintf(stderr, "error: invalid style attribute %s\n", attr); + fprintf(stderr, "error: invalid style attribute '%s'\n", attr); return 1; } return 0; @@ -336,6 +336,9 @@ static struct {const char *n; struct style *s;} ini_objects[] = { {"quote_x", &styles.quote_x}, }; +/* object attribute value */ +#define STYLE_LINE_FORMAT "%127[0-9A-Za-z_-].%127[0-9a-zA-Z_-] = %127s" + static int parse_styleset(void) { bool in_section = false; @@ -356,10 +359,10 @@ static int parse_styleset(void) /* strip LF, CR, CRLF, LFCR */ buf[strcspn(buf, "\r\n")] = '\0'; if (in_section) { - char obj[64], attr[64], val[64]; + char obj[128], attr[128], val[128]; bool changed = false; - if (sscanf(buf, "%63[^.].%63[^=] = %63s", obj, attr, val) != 3) { + if (sscanf(buf, STYLE_LINE_FORMAT, obj, attr, val) != 3) { if (buf[0] == '[') { /* start of another section */ break; diff --git a/filters/test.sh b/filters/test.sh index 78a52fff..c0d9e6cd 100755 --- a/filters/test.sh +++ b/filters/test.sh @@ -4,6 +4,31 @@ set -e here=$(dirname $0) fail=0 +style=$(mktemp) +trap "rm -f $style" EXIT +cat >$style < -Date: Mon, 26 Dec 2022 17:02:14 +0100 -Subject: [PATCH aerc] doc: fix numbered lists +From: Robin Jarry <]8;id=colorize-0;mailto://robin@jarry.cc\robin@jarry.cc]8;;\> +Date: Mon, 26 Dec 2022 17:02:14 +0100 +Subject: [PATCH aerc] doc: fix numbered lists According to scdoc(5), numbered lists start with a period. -Fixes: af63bd0188d1 ("doc: homogenize scdoc markup") -Signed-off-by: Robin Jarry <]8;id=colorize-1;mailto://robin@jarry.cc\robin@jarry.cc]8;;\> +Fixes: af63bd0188d1 ("doc: homogenize scdoc markup") +Signed-off-by: Robin Jarry <]8;id=colorize-1;mailto://robin@jarry.cc\robin@jarry.cc]8;;\> --- doc/aerc-stylesets.7.scd | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -diff --git a/doc/aerc-stylesets.7.scd b/doc/aerc-stylesets.7.scd -index d82ba7cf8163..34bbf4af0fc5 100644 ---- a/doc/aerc-stylesets.7.scd -+++ b/doc/aerc-stylesets.7.scd -@@ -180,20 +180,20 @@ that style applies, unless overridden by a higher layer. +diff --git a/doc/aerc-stylesets.7.scd b/doc/aerc-stylesets.7.scd +index d82ba7cf8163..34bbf4af0fc5 100644 +--- a/doc/aerc-stylesets.7.scd ++++ b/doc/aerc-stylesets.7.scd +@@ -180,20 +180,20 @@ that style applies, unless overridden by a higher layer. The order that *msglist_\** styles are applied in is, from first to last: --1. *msglist_default* --2. *msglist_unread* --3. *msglist_read* --4. *msglist_flagged* --5. *msglist_deleted* --6. *msglist_marked* -+. *msglist_default* -+. *msglist_unread* -+. *msglist_read* -+. *msglist_flagged* -+. *msglist_deleted* -+. *msglist_marked* +-1. *msglist_default* +-2. *msglist_unread* +-3. *msglist_read* +-4. *msglist_flagged* +-5. *msglist_deleted* +-6. *msglist_marked* ++. *msglist_default* ++. *msglist_unread* ++. *msglist_read* ++. *msglist_flagged* ++. *msglist_deleted* ++. *msglist_marked* So, the marked style will override all other msglist styles. The order for *dirlist_\** styles is: --1. *dirlist_default* --2. *dirlist_unread* --3. *dirlist_recent* -+. *dirlist_default* -+. *dirlist_unread* -+. *dirlist_recent* +-1. *dirlist_default* +-2. *dirlist_unread* +-3. *dirlist_recent* ++. *dirlist_default* ++. *dirlist_unread* ++. *dirlist_recent* ## COLORS ---  -2.39.0 - +--  +2.39.0 + diff --git a/filters/vectors/colorize-quotes.expected b/filters/vectors/colorize-quotes.expected index 5cb4dacc..4e1e643c 100644 --- a/filters/vectors/colorize-quotes.expected +++ b/filters/vectors/colorize-quotes.expected @@ -1,26 +1,26 @@ Foo Bar, xxxxx: -> Lorem ipsum dolor sit amet, insolens adolescens ne usu? In pri denique -> argumentum, te autem decore convenire mea! Duo nisl esse an, aliquid -> conceptam sea cu. Ignota copiosae gubergren ad est, ut illum doming vocibus -> sed. Et vis nulla expetendis mediocritatem, errem option gloriatur at nam? -> Brute vidisse corpora ut his, sonet omnesque adipiscing ea quo, cum ea errem -> aliquip reformidans? +> Lorem ipsum dolor sit amet, insolens adolescens ne usu? In pri denique +> argumentum, te autem decore convenire mea! Duo nisl esse an, aliquid +> conceptam sea cu. Ignota copiosae gubergren ad est, ut illum doming vocibus +> sed. Et vis nulla expetendis mediocritatem, errem option gloriatur at nam? +> Brute vidisse corpora ut his, sonet omnesque adipiscing ea quo, cum ea errem +> aliquip reformidans? Magna delicatissimi ei vel? Quem petentium scribentur eum ne? Et inani debet cetero mea, sint conceptam efficiendi mel te. Qui ut senserit interesset, per nibh petentium at! Sit docendi laboramus ei, animal insolens ad mea. ->> Nostrud alienum nec in, illum errem audiam no per! Saepe alterum vis ea! Ei ->> quis minim ius, ut eos mandamus salutandi. Lorem facilisis in nam, ridens ->> principes sadipscing et eum, pri graecis singulis ut. Mea dolor primis ->> impetus in, his epicurei tacimates id, vis labitur suscipit ad. -> Erat alienum interpretaris has et, te vim aliquam molestie. Nam vivendum -> facilisis qualisque at, ex his mucius qualisque! Fabulas lucilius adversarium -> eu his. Cu soluta inermis accusata usu, his nulla dolore ne, vis id semper -> detracto sententia <]8;id=colorize-0;https://foobar.com\https://foobar.com]8;;\> && "]8;id=colorize-1;https://foobaz.org/\https://foobaz.org/]8;;\". -> -> Error libris deleniti ea mei, vis at elit probo munere, his sint unum -> albucius ex. []8;id=colorize-2;https://pouet.com/oksuper\https://pouet.com/oksuper]8;;\](]8;id=colorize-3;https://pouet.com/oksuper\https://pouet.com/oksuper]8;;\). +>> Nostrud alienum nec in, illum errem audiam no per! Saepe alterum vis ea! Ei +>> quis minim ius, ut eos mandamus salutandi. Lorem facilisis in nam, ridens +>> principes sadipscing et eum, pri graecis singulis ut. Mea dolor primis +>> impetus in, his epicurei tacimates id, vis labitur suscipit ad. +> Erat alienum interpretaris has et, te vim aliquam molestie. Nam vivendum +> facilisis qualisque at, ex his mucius qualisque! Fabulas lucilius adversarium +> eu his. Cu soluta inermis accusata usu, his nulla dolore ne, vis id semper +> detracto sententia <]8;id=colorize-0;https://foobar.com\https://foobar.com]8;;\> && "]8;id=colorize-1;https://foobaz.org/\https://foobaz.org/]8;;\". +> +> Error libris deleniti ea mei, vis at elit probo munere, his sint unum +> albucius ex. []8;id=colorize-2;https://pouet.com/oksuper\https://pouet.com/oksuper]8;;\](]8;id=colorize-3;https://pouet.com/oksuper\https://pouet.com/oksuper]8;;\). Graece definiebas scripserit ne est? Nec nonumes explicari contentiones ne, vocent iuvaret placerat no vix. Nec et partem salutandi deseruisse, his no @@ -28,38 +28,38 @@ possim malorum pericula. Te quando reprehendunt nam, at consul sadipscing vel? Velit possim aliquando ei per, ne simul quodsi antiopam sea, ullum choro facilisi et pri http:// or https://! -> Dico soleat partem ea pro, ad vix impetus splendide. Primis melius principes -> pri ad, tacimates pertinacia ei pro? Appareat atomorum oportere at nam, eu -> per quod minim reprimique, ornatus graecis ad vel. Malis vulputate ea qui, -> eum tacimates recteque et, usu ea dolore vidisse. Brute mediocrem molestiae -> sed te. No stet prompta pri, rebum populo nominati eos te. -> -> diff --git a/foo b/foo -> index 4b0fe8dded3a..518b67134639 100644 -> --- a/foo -> +++ b/foo -> @@ -131,6 +131,83 @@ func pouet() int { -> err := doThis() ->  -> - err2 := doThat() -> + err2 := notDoThat() ->  -> if err != nil || err2 != nil { +> Dico soleat partem ea pro, ad vix impetus splendide. Primis melius principes +> pri ad, tacimates pertinacia ei pro? Appareat atomorum oportere at nam, eu +> per quod minim reprimique, ornatus graecis ad vel. Malis vulputate ea qui, +> eum tacimates recteque et, usu ea dolore vidisse. Brute mediocrem molestiae +> sed te. No stet prompta pri, rebum populo nominati eos te. +> +> diff --git a/foo b/foo +> index 4b0fe8dded3a..518b67134639 100644 +> --- a/foo +> +++ b/foo +> @@ -131,6 +131,83 @@ func pouet() int { +> err := doThis() +>  +> - err2 := doThat() +> + err2 := notDoThat() +>  +> if err != nil || err2 != nil { Id vix referrentur philosophia, veri labores an nec. Noster denique no duo, sit -ei diam inermis vocibus! Mutat principes ex pro, at ]8;id=colorize-4;mailto://~rjarry/aerc-devel@lists.sr.ht\~rjarry/aerc-devel@lists.sr.ht]8;;\. +ei diam inermis vocibus! Mutat principes ex pro, at ]8;id=colorize-4;mailto://~rjarry/aerc-devel@lists.sr.ht\~rjarry/aerc-devel@lists.sr.ht]8;;\. Has putent verterem constituto ex, tale electram duo at! Ei nulla lucilius intellegat nam, pro quod epicuri dissentiet ut, omnis voluptatibus definitiones -vim at []8;id=colorize-5;irc://foo.bar\irc://foo.bar]8;;\] <]8;id=colorize-6;mailto://jeanpierre@foobaz.org\jeanpierre@foobaz.org]8;;\>. +vim at []8;id=colorize-5;irc://foo.bar\irc://foo.bar]8;;\] <]8;id=colorize-6;mailto://jeanpierre@foobaz.org\jeanpierre@foobaz.org]8;;\>. -]8;id=colorize-7;https://git-man-page-generator.lokaltog.net/#Y2xhcCQkY29tbWFuZA==\https://git-man-page-generator.lokaltog.net/#Y2xhcCQkY29tbWFuZA==]8;;\ +]8;id=colorize-7;https://git-man-page-generator.lokaltog.net/#Y2xhcCQkY29tbWFuZA==\https://git-man-page-generator.lokaltog.net/#Y2xhcCQkY29tbWFuZA==]8;;\ Eam mundi libris debitis ad, eam regione numquam at. Eum omnes bonorum eu, oporteat assueverit disputationi nam ne, nonumes iracundia mea ad! Duo libris recusabo id, ceteros salutatus inciderint vim ea. Et graeco reformidans vel? Ei -has labore quidam ]8;id=colorize-8;https://foobaz.com/ooookf\https://foobaz.com/ooookf]8;;\? +has labore quidam ]8;id=colorize-8;https://foobaz.com/ooookf\https://foobaz.com/ooookf]8;;\? ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> sympa, non? +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> sympa, non? ---  -Batman +--  +Batman -- cgit