Skip to content

Commit

Permalink
Cope with embedded spaces such as 'Content-Type: 7 bit'
Browse files Browse the repository at this point in the history
The main complication is that we want to handle headers like that, but don't
want to copy trailing spaces into the result (since some (other) mailers appear
to add trailing spaces.)
  • Loading branch information
rc0 committed Sep 9, 2006
1 parent e019a29 commit daa20ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions nvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 139,7 @@ struct nvp *make_nvp(char *s)/*{{{*/
current_action = nvp_action[current_state];
switch (current_action) {
case GOT_NAME:
case GOT_NAME_TRAILING_SPACE:
case GOT_MAJORMINOR:
case GOT_NAMEVALUE:
last_action = current_action;
Expand All @@ -149,6 150,11 @@ struct nvp *make_nvp(char *s)/*{{{*/
*nn = 0;
append_name(result, name);
break;
case GOT_NAME_TRAILING_SPACE:
while (isspace(*--nn)) {}
* nn = 0;
append_name(result, name);
break;
case GOT_MAJORMINOR:
*nn = 0;
*mm = 0;
Expand Down
17 changes: 14 additions & 3 deletions nvp.nfa
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,6 @@ Tokens EOS
Abbrev VALUE = [\041-~]~[\\";]
Abbrev QVALUE = VALUE | [\040;] | <escape:in->out>
Abbrev NAME1 = [0-9a-zA-Z_\-]
Abbrev NAME2 = NAME1 | [0-9\-]
Abbrev OWS = <optwhite:in->out>

%{
Expand All @@ -44,15 43,26 @@ Block optwhite {
}

Block name {
# This needs to cope with embedded spaces, e.g. for mailers that write '7
# bit' instead of '7bit'
State in
NAME1 -> name1

State name1
= COPY_TO_NAME
NAME2 -> name1
= GOT_NAME
NAME1 -> name1
[ \t] -> name2
-> out

State name2
= COPY_TO_NAME
= GOT_NAME_TRAILING_SPACE
[ \t] -> name2
NAME1 -> name1
-> out

State out = GOT_NAME
State out
}

Block value {
Expand Down Expand Up @@ -150,6 160,7 @@ Prefix nvp
Group action {
Attr GOT_NAMEVALUE
Attr GOT_NAME
Attr GOT_NAME_TRAILING_SPACE
Attr GOT_MAJORMINOR
Attr GOT_TERMINATOR
Defattr GOT_NOTHING
Expand Down
1 change: 1 addition & 0 deletions nvptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 26,7 @@
enum nvp_action {
GOT_NAMEVALUE,
GOT_NAME,
GOT_NAME_TRAILING_SPACE,
GOT_MAJORMINOR,
GOT_TERMINATOR,
GOT_NOTHING
Expand Down

0 comments on commit daa20ea

Please sign in to comment.