@@ -39,13 +39,21 @@ function dateVows(table) {
3939 Object . keys ( table ) . forEach ( function ( date ) {
4040 var expect = table [ date ] ;
4141 theVows [ date ] = function ( ) {
42- var got = tough . parseDate ( date ) ? 'valid' : 'invalid' ;
43- assert . equal ( got , expect ? 'valid' : 'invalid' ) ;
42+ var got = tough . parseDate ( date ) ? true : false ;
43+ if ( expect && ! got ) {
44+ assert . ok ( false , "expected valid date but was invalid" ) ;
45+ } else if ( ! expect && got ) {
46+ assert . ok ( false , "expected invalid date but was valid" ) ;
47+ } else {
48+ assert . ok ( true ) ;
49+ }
4450 } ;
4551 } ) ;
4652 return { "date parsing" : theVows } ;
4753}
4854
55+ var TOO_MANY_XS = 'x' . repeat ( 65535 ) ;
56+
4957vows
5058 . describe ( 'Date' )
5159 . addBatch ( dateVows ( {
5563 "18 Oct 2011 07:42:42 GMT" : true ,
5664 "8 Oct 2011 7:42:42 GMT" : true ,
5765 "8 Oct 2011 7:2:42 GMT" : true ,
66+ "8 Oct 2011 7:2:2 GMT" : true ,
5867 "Oct 18 2011 07:42:42 GMT" : true ,
5968 "Tue Oct 18 2011 07:05:03 GMT+0000 (GMT)" : true ,
6069 "09 Jun 2021 10:18:14 GMT" : true ,
6473 '01 Jan 1601 00:00:00 GMT' : true ,
6574 '10 Feb 81 13:00:00 GMT' : true , // implicit year
6675 'Thu, 17-Apr-2014 02:12:29 GMT' : true , // dashes
67- 'Thu, 17-Apr-2014 02:12:29 UTC' : true // dashes and UTC
76+ 'Thu, 17-Apr-2014 02:12:29 UTC' : true , // dashes and UTC
77+
78+ // garbage after parts:
79+ "Wedxxx, 09 Jun 2021 10:18:14 GMT" : true , // day of week doesn't matter
80+ "Wed, 09e9 Jun 2021 10:18:14 GMT" : true , // garbage after day ignored
81+ "Wed, 09 Junxxx 2021 10:18:14 GMT" : true , // prefix match on month
82+ "Wed, 09 Jun 2021e9 10:18:14 GMT" : true , // garbage after year OK
83+ "Wed, 09 Jun 2021 10e9:18:14 GMT" : false , // can't have garbage after HH
84+ "Wed, 09 Jun 2021 10:18e9:14 GMT" : false , // can't have garbage after MM
85+ "Wed, 09 Jun 2021 10:18:14e9 GMT" : true , // garbage after SS ignored
86+
87+ // extra digit in time parts:
88+ "Thu, 01 Jan 1970 000:00:01 GMT" : false ,
89+ "Thu, 01 Jan 1970 00:000:01 GMT" : false ,
90+ "Thu, 01 Jan 1970 00:00:010 GMT" : false ,
91+
92+ "" : false
6893 } ) )
6994 . addBatch ( {
70- "strict date parse of Thu, 01 Jan 1970 00:00:010 GMT " : {
95+ "reDos hr " : {
7196 topic : function ( ) {
72- return tough . parseDate ( 'Thu, 01 Jan 1970 00:00:010 GMT' , true ) ? true : false ;
97+ var str = "Wed, 09 Jun 2021 10" + TOO_MANY_XS + ":18:14 GMT" ;
98+ return tough . parseDate ( str , true ) ? true : false ;
7399 } ,
74100 "invalid" : function ( date ) {
75101 assert . equal ( date , false ) ;
76102 }
103+ } ,
104+ "reDos min" : {
105+ topic : function ( ) {
106+ var str = "Wed, 09 Jun 2021 10:18" + TOO_MANY_XS + ":14 GMT" ;
107+ return tough . parseDate ( str , true ) ? true : false ;
108+ } ,
109+ "invalid" : function ( date ) {
110+ assert . equal ( date , false ) ;
111+ }
112+ } ,
113+ "reDos sec" : {
114+ topic : function ( ) {
115+ var str = "Wed, 09 Jun 2021 10:18:14" + TOO_MANY_XS + " GMT" ;
116+ return tough . parseDate ( str , true ) ? true : false ;
117+ } ,
118+ "valid" : function ( date ) {
119+ assert . equal ( date , true ) ;
120+ }
77121 }
78122 } )
79123 . export ( module ) ;
0 commit comments