Author: Pietro Abate <pietro.abate@pps.univ-paris-diderot.fr>
Description: Parsing Debian field names: accept any characters that are
  authorized by Debian Policy
Debian-bug: 811569
Upstream-commit: 24d2fa5f924e2159b3e395adfbbf5bcde4ee7e91

Index: dose3/common/format822_lexer.mll
===================================================================
--- dose3.orig/common/format822_lexer.mll	2016-01-30 15:10:19.296935779 +0100
+++ dose3/common/format822_lexer.mll	2016-01-30 15:10:19.296935779 +0100
@@ -12,6 +12,17 @@
 (*  library, see the COPYING file for more information.                      *)
 (*****************************************************************************)
 
+(*
+Debian Policy : https://www.debian.org/doc/debian-policy/ch-controlfields.html
+
+Each paragraph consists of a series of data fields. Each field consists of the
+field name followed by a colon and then the data/value associated with that
+field. The field name is composed of US-ASCII characters excluding control
+characters, space, and colon (i.e., characters in the ranges 33-57 and 59-126,
+inclusive). Field names must not begin with the comment character, #, nor with
+the hyphen character, -.
+*)
+
 {
   open Format822_parser
 
@@ -29,19 +40,20 @@
 let letter = lower_letter | upper_letter
 let digit = [ '0' - '9' ]
 let blank = [ ' ' '\t' ]
-let ident = (letter | digit | '-')+
+let ident = ( [ '!' - '9'] | [';' - '~' ] )+
+let identnosharphypen = ( '!' | '"' | [ '$' - ',' ] | [ '.' - '9'] | [';' - '~' ] )
+(* conform to the Debian Policy *)
+let fieldname = (identnosharphypen ident)
 
 rule token_822 = parse
-  | "-----BEGIN PGP SIGNED MESSAGE-----" { PGPHEAD }
-  | "-----BEGIN PGP SIGNATURE-----" { pgpsignature lexbuf }
-  | (ident as field) ':' blank*
-    ([^'\n']* as rest)          { FIELD(field, (get_range lexbuf, rest)) }
-  | blank ([^'\n']* as rest)    { CONT(get_range lexbuf, rest) }
-(*  | '#' [^'\n']* ('\n'|eof)     { token_822 lexbuf } *)
-  | blank* '\n'                 { Lexing.new_line lexbuf; BLANKLINE }
-  | eof                         { EOF }
-  | _ as c                      { raise_error lexbuf c }
+  | "-----BEGIN PGP SIGNED MESSAGE-----"               { PGPHEAD }
+  | "-----BEGIN PGP SIGNATURE-----"                    { pgpsignature lexbuf }
+  | '#' [^'\n']* ('\n'|eof)                            { token_822 lexbuf }
+  | (fieldname as field) ':' blank* ([^'\n']* as rest) { FIELD(field, (get_range lexbuf, rest)) }
+  | blank ([^'\n']* as rest)                           { CONT(get_range lexbuf, rest) }
+  | blank* '\n'                                        { Lexing.new_line lexbuf; BLANKLINE }
+  | eof                                                { EOF }
+  | _ as c                                             { raise_error lexbuf c }
 and pgpsignature = parse
-    | "-----END PGP SIGNATURE-----"  { token_822 lexbuf    }
-    | _                              { pgpsignature lexbuf }
-
+    | "-----END PGP SIGNATURE-----"                    { token_822 lexbuf    }
+    | _                                                { pgpsignature lexbuf }
