Make PGN parser immune to unprotected time stamps
authorH.G. Muller <h.g.muller@hccnet.nl>
Mon, 20 May 2013 09:14:01 +0000 (11:14 +0200)
committerH.G. Muller <h.g.muller@hccnet.nl>
Tue, 27 Aug 2013 07:36:40 +0000 (09:36 +0200)
The parser choked on time stamps of the form dd:dd or dd:dd:dd if one
of the fields happened to be 00, because it wouldmistake that for a
non-compliant king-side castling. By excluding this interpretation when
the 00 is immediately preceded or followed by ':' this is now prevented.

parser.c

index e0b4ff4..6da13d4 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -353,7 +353,7 @@ badMove:// we failed to find algebraic move
        }
 
        // ********* SAN Castings *************************************
-       if(**p == 'O' || **p == 'o' || **p == '0') {
+       if(**p == 'O' || **p == 'o' || **p == '0' && !Match("00:", p)) { // exclude 00 in time stamps
            int castlingType = 0;
            if(Match("O-O-O", p) || Match("o-o-o", p) || Match("0-0-0", p) ||
               Match("OOO", p) || Match("ooo", p) || Match("000", p)) castlingType = 2;
@@ -532,6 +532,8 @@ badMove:// we failed to find algebraic move
            return Nothing;
        }
 
+       // ********* Prevent 00 in unprotected time stamps to be mistaken for castling *******
+       if(Match(":00", p)) return Nothing;
 
        // ********* Could not match to anything. Return offending character ****
        (*p)++;