1+ /**
2+ * Valid months that are allowed to be in an IMF date
3+ */
14const IMF_DAYS = [ 'mon' , 'tue' , 'wed' , 'thu' , 'fri' , 'sat' , 'sun' ] ;
5+
6+ /**
7+ * Specific locations that are expected to be spaces in an IMF date
8+ */
29const IMF_SPACES = [ 4 , 7 , 11 , 16 , 25 ] ;
10+
11+ /**
12+ * Valid months that are allowed to be in an IMF date
13+ */
314const IMF_MONTHS = [
415 'jan' ,
516 'feb' ,
@@ -14,10 +25,20 @@ const IMF_MONTHS = [
1425 'nov' ,
1526 'dec' ,
1627] ;
28+
29+ /**
30+ * Specific locations that are expected to be colons in an IMF date
31+ */
1732const IMF_COLONS = [ 19 , 22 ] ;
1833
34+ /**
35+ * Specific locations that are expected to be spaces in an asctime() date
36+ */
1937const ASCTIME_SPACES = [ 3 , 7 , 10 , 19 ] ;
2038
39+ /**
40+ * Valid days allowed in an RF850 date
41+ */
2142const RFC850_DAYS = [
2243 'monday' ,
2344 'tuesday' ,
@@ -39,7 +60,7 @@ export function parseHttpDate(
3960 // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
4061 // Sunday, 06-Nov-94 08:49:37 GMT ; obsolete RFC 850 format
4162
42- if ( ! date ) {
63+ if ( date === null ) {
4364 return undefined ;
4465 }
4566
@@ -68,12 +89,14 @@ function parseImfDate(date: string): Date | undefined {
6889 return undefined ;
6990 }
7091
92+ // Ensure there are spaces in the expected locations
7193 for ( const spaceInx of IMF_SPACES ) {
7294 if ( date [ spaceInx ] !== ' ' ) {
7395 return undefined ;
7496 }
7597 }
7698
99+ // Ensure there are colons in the expected locations
77100 for ( const colonIdx of IMF_COLONS ) {
78101 if ( date [ colonIdx ] !== ':' ) {
79102 return undefined ;
@@ -134,6 +157,7 @@ function parseAscTimeDate(date: string): Date | undefined {
134157 return undefined ;
135158 }
136159
160+ // Ensure there are spaces in the expected locations
137161 for ( const spaceIdx of ASCTIME_SPACES ) {
138162 if ( date [ spaceIdx ] !== ' ' ) {
139163 return undefined ;
@@ -206,6 +230,7 @@ function parseRfc850Date(date: string, now = new Date()): Date | undefined {
206230 return undefined ;
207231 }
208232
233+ // Ensure there are spaces, dashes, and colons in the expected locations
209234 if (
210235 date [ commaIndex + 1 ] !== ' ' ||
211236 date [ commaIndex + 4 ] !== '-' ||
0 commit comments