ion-js icon indicating copy to clipboard operation
ion-js copied to clipboard

`ion-js` parses malformed timestamps as valid Ion

Open popematt opened this issue 3 years ago • 0 comments

The Ion Spec says

In the text notation, timestamp values must be followed by one of the fifteen numeric stop-characters: {}[](),\"\'\ \t\n\r\v\f.

However, ion-js allows almost any character after a timestamp when the timestamp has a precision of year or month. Here are some examples of invalid Ion that are incorrectly accepted by ion-js.

Invalid Input Parsed As
2001TZ 2001T 'Z'
2001T+inf 2001T +inf
2001-01T10.00 2001-01T 10.00
(2001-01TZ+10) ( 2001-01T 'Z' '+' 10 )
(2001-01T.0.10) ( 2001-01T '.' 0.10 )
2001-01Tnull.bool 2001-01T null.bool

The probable cause is that there is no check for a numeric stop character after the T for the YYYY and YYYY-MM branches of _readTimestamp(). https://github.com/amzn/ion-js/blob/b5f6ab34707b57767b54f55845ae97ebb77b248f/src/IonParserTextRaw.ts#L1093-L1110

popematt avatar Sep 08 '22 22:09 popematt