From 81c6c11d707840e54f9bb4a8042b531797de6cb0 Mon Sep 17 00:00:00 2001 From: "Steffen (Daode) Nurpmeso" Date: Sat, 22 Apr 2017 22:35:03 +0200 Subject: [PATCH] a_head_addrspec_check(): in quoted-string, only quoted-pairize " and \ --- cc-test.sh | 12 ++++++------ head.c | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cc-test.sh b/cc-test.sh index 2b380166..7101e2fc 100755 --- a/cc-test.sh +++ b/cc-test.sh @@ -1534,7 +1534,7 @@ t_behave_addrcodec() { eval vput addrcodec res d $res echo $?/$^ERRNAME $res # - vput addrcodec res +++e 22 Hey\,\" "Wie()" findet \" Dr. \" das? + vput addrcodec res +++e 22 Hey\\,\" "Wie()" findet \" Dr. \" das? echo $?/$^ERRNAME $res eval vput addrcodec res d $res echo $?/$^ERRNAME $res @@ -1549,9 +1549,9 @@ t_behave_addrcodec() { #0/NONE 2 . #0/NONE "3 Sauer Dr." #0/NONE 3 Sauer Dr. -#0/NONE 3.50 "Sauer \(Ma\) Dr." +#0/NONE "3.50 Sauer (Ma) Dr." #0/NONE 3.50 Sauer (Ma) Dr. -#0/NONE 3.51 "Sauer \(Ma\) \"Dr.\"" +#0/NONE "3.51 Sauer (Ma) \"Dr.\"" #0/NONE 3.51 Sauer (Ma) "Dr." #0/NONE 4 Sauer (Ma) "Dr." #0/NONE 4 Sauer (Ma) Dr. @@ -1588,11 +1588,11 @@ t_behave_addrcodec() { #1/INVAL 20 Hey\\,\\" "Wie()" findet \\" Dr. \\" das? #0/NONE "21 Hey\\,\\ Wie() findet \\ Dr. \\ das?" #0/NONE 21 Hey\,\ Wie() findet \ Dr. \ das? -#0/NONE "22 Hey\,\" Wie() findet \" Dr. \" das?" -#0/NONE 22 Hey," Wie() findet " Dr. " das? +#0/NONE "22 Hey\\,\" Wie() findet \" Dr. \" das?" +#0/NONE 22 Hey\," Wie() findet " Dr. " das? #0/NONE doog@def ex0_test behave:addrcodec - cksum_test behave:addrcodec "${MBOX}" '3907388894 2416' + cksum_test behave:addrcodec "${MBOX}" '429099645 2414' } t_behave_vexpr() { diff --git a/head.c b/head.c index 5355a746..2e9ee644 100644 --- a/head.c +++ b/head.c @@ -520,9 +520,11 @@ jaddr_check: }else{ /* If we seem to know that this is an address. Ensure this is correct * according to RFC 5322 TODO the entire address parser should be like - * TODO that for one, and then we should now whether structured or + * TODO that for one, and then we should know whether structured or * TODO unstructured, and just parse correctly overall! - * TODO In addition, this can be optimised a lot */ + * TODO In addition, this can be optimised a lot. + * TODO And it is far from perfect: it should not forget whether no + * TODO whitespace followed some snippet, and it was written hastily */ struct a_token{ struct a_token *t_last; struct a_token *t_next; @@ -707,7 +709,7 @@ jnode_redo: /* Nothing may follow the address, move it to the end */ if(!(tcurr->t_f & a_T_TADDR)){ - for(tp = thead; tp != NULL; tp = tp->t_next) + for(tp = thead; tp != NULL; tp = tp->t_next){ if(tp->t_f & a_T_TADDR){ if(tp->t_last != NULL) tp->t_last->t_next = tp->t_next; @@ -724,6 +726,7 @@ jnode_redo: tcurr->t_next = NULL; break; } + } } /* Make ranges contiguous: ensure a continuous range of atoms is converted @@ -738,6 +741,7 @@ jnode_redo: tp->t_f |= a_T_SPECIAL; } } + /* And yes, we want quotes to extend as much as possible */ for(tp = thead; tp != NULL; tp = tp->t_next){ if(tp->t_f & a_T_TQUOTE){ @@ -772,7 +776,7 @@ jnode_redo: (tcurr->t_end - tcurr->t_start)); while((tp = tcurr->t_next) != NULL && (tp->t_f & a_T_TCOMM)){ tcurr = tp; - ostp = n_string_push_c(ostp, ' '); + ostp = n_string_push_c(ostp, ' '); /* XXX may be artificial */ ostp = n_string_push_buf(ostp, &cp1st[tcurr->t_start], (tcurr->t_end - tcurr->t_start)); } @@ -797,9 +801,10 @@ jput_quote: bool_t esc; for(esc = FAL0; cp < cpmax;){ - if((c.c = *cp++) == '\\' && !esc) - esc = TRU1; - else{ + if((c.c = *cp++) == '\\' && !esc){ + if(cp < cpmax && (*cp == '"' || *cp == '\\')) + esc = TRU1; + }else{ if(esc || c.c == '"'){ jput_quote_esc: ostp = n_string_push_c(ostp, '\\'); -- 2.11.4.GIT