Skip to content

Commit 28bad72

Browse files
ashsearlegkalpak
authored andcommitted
fix(dateFilter): correctly handle newlines in format string
Fixes angular#15794 Closes angular#15792
1 parent 1daa4f2 commit 28bad72

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/ng/filter/filters.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ var DATE_FORMATS = {
475475
GGGG: longEraGetter
476476
};
477477

478-
var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|m+|s+|a|Z|G+|w+))(.*)/,
478+
var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|m+|s+|a|Z|G+|w+))([\s\S]*)/,
479479
NUMBER_STRING = /^-?\d+$/;
480480

481481
/**
@@ -534,6 +534,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+
534534
* `"h 'in the morning'"`). In order to output a single quote, escape it - i.e., two single quotes in a sequence
535535
* (e.g. `"h 'o''clock'"`).
536536
*
537+
* Any other characters in the `format` string will be output as-is.
538+
*
537539
* @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or
538540
* number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its
539541
* shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is

test/ng/filter/filtersSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ describe('filters', function() {
504504
expect(date(morning, 'yy/xxx')).toEqual('10/xxx');
505505
});
506506

507+
it('should allow newlines in format', function() {
508+
expect(date(midnight, 'EEE\nMMM d\'\n\'yy/xxx\n')).toEqual('Fri\nSep 3\n10/xxx\n');
509+
});
510+
507511
it('should support various iso8061 date strings with timezone as input', function() {
508512
var format = 'yyyy-MM-dd ss';
509513

0 commit comments

Comments
 (0)