@@ -39,13 +39,21 @@ function dateVows(table) {
39
39
Object . keys ( table ) . forEach ( function ( date ) {
40
40
var expect = table [ date ] ;
41
41
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
+ }
44
50
} ;
45
51
} ) ;
46
52
return { "date parsing" : theVows } ;
47
53
}
48
54
55
+ var TOO_MANY_XS = 'x' . repeat ( 65535 ) ;
56
+
49
57
vows
50
58
. describe ( 'Date' )
51
59
. addBatch ( dateVows ( {
55
63
"18 Oct 2011 07:42:42 GMT" : true ,
56
64
"8 Oct 2011 7:42:42 GMT" : true ,
57
65
"8 Oct 2011 7:2:42 GMT" : true ,
66
+ "8 Oct 2011 7:2:2 GMT" : true ,
58
67
"Oct 18 2011 07:42:42 GMT" : true ,
59
68
"Tue Oct 18 2011 07:05:03 GMT+0000 (GMT)" : true ,
60
69
"09 Jun 2021 10:18:14 GMT" : true ,
64
73
'01 Jan 1601 00:00:00 GMT' : true ,
65
74
'10 Feb 81 13:00:00 GMT' : true , // implicit year
66
75
'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
68
93
} ) )
69
94
. addBatch ( {
70
- "strict date parse of Thu, 01 Jan 1970 00:00:010 GMT " : {
95
+ "reDos hr " : {
71
96
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 ;
73
99
} ,
74
100
"invalid" : function ( date ) {
75
101
assert . equal ( date , false ) ;
76
102
}
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
+ }
77
121
}
78
122
} )
79
123
. export ( module ) ;
0 commit comments