Skip to content

Commit 32cc675

Browse files
DzmitryShylovichmhevery
authored andcommitted
fix(common): DatePipe doesn't throw for NaN (angular#14117)
Fixes angular#14103 PR Close angular#14117
1 parent d5f1419 commit 32cc675

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

‎modules/@angular/common/src/pipes/date_pipe.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class DatePipe implements PipeTransform {
103103
transform(value: any, pattern: string = 'mediumDate'): string {
104104
let date: Date;
105105

106-
if (isBlank(value)) return null;
106+
if (isBlank(value) || value !== value) return null;
107107

108108
if (typeof value === 'string') {
109109
value = value.trim();

‎modules/@angular/common/test/pipes/date_pipe_spec.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export function main() {
5353

5454
it('should return null for empty string', () => expect(pipe.transform('')).toEqual(null));
5555

56+
it('should return null for NaN', () => expect(pipe.transform(Number.NaN)).toEqual(null));
57+
5658
it('should support ISO string without time',
5759
() => { expect(() => pipe.transform(isoStringWithoutTime)).not.toThrow(); });
5860

0 commit comments

Comments
 (0)