@@ -590,6 +590,18 @@ export function maxValue() {
590590 return DateTime ( 253402300799999 , DateTimeKind . Utc ) ;
591591}
592592
593+ // The only date words .NET's invariant parser recognises: month names, weekday names,
594+ // meridiem designators and zone markers (plus the ISO "T" separator). Anything else is
595+ // rejected. Used to reject JS-permissive inputs (see `parseRaw`).
596+ const recognizedDateWords = new Set ( [
597+ "january" , "february" , "march" , "april" , "may" , "june" ,
598+ "july" , "august" , "september" , "october" , "november" , "december" ,
599+ "jan" , "feb" , "mar" , "apr" , "jun" , "jul" , "aug" , "sep" , "sept" , "oct" , "nov" , "dec" ,
600+ "monday" , "tuesday" , "wednesday" , "thursday" , "friday" , "saturday" , "sunday" ,
601+ "mon" , "tue" , "wed" , "thu" , "fri" , "sat" , "sun" ,
602+ "am" , "pm" , "gmt" , "utc" , "ut" , "t" , "z" ,
603+ ] ) ;
604+
593605export function parseRaw ( input : string ) : [ Date , Offset ] {
594606 function fail ( ) {
595607 throw new Exception ( `The string is not a valid Date: ${ input } ` ) ;
@@ -599,12 +611,7 @@ export function parseRaw(input: string): [Date, Offset] {
599611 fail ( ) ;
600612 }
601613
602- // Pre-validate: reject strings that JavaScript's Date constructor accepts but .NET does not.
603- // JS Date (V8) is overly permissive — e.g. "ABC 6" is accepted because V8 treats "ABC" as a
604- // timezone abbreviation. .NET DateTime.TryParse requires a recognisable date format.
605- // Valid date strings must start with a digit, or with a recognised month name (Jan–Dec).
606- // See #3858.
607- if ( ! / ^ \s * (?: \d | J a n | F e b | M a r | A p r | M a y | J u n | J u l | A u g | S e p | O c t | N o v | D e c ) / i. test ( input ) ) {
614+ if ( ( input . match ( / [ a - z ] + / gi) ?? [ ] ) . some ( word => ! recognizedDateWords . has ( word . toLowerCase ( ) ) ) ) {
608615 fail ( ) ;
609616 }
610617
0 commit comments