From 81c32f9cdbf42e972c1ebd9bd78c2cb687fa17d1 Mon Sep 17 00:00:00 2001 From: Ash Searle Date: Thu, 9 Mar 2017 20:16:05 +0000 Subject: [PATCH 1/2] fix(date filter): handle newlines in format string Closes #15794 --- src/ng/filter/filters.js | 2 +- test/ng/filter/filtersSpec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index e6d4ed06a0eb..3e97e7cebd15 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -475,7 +475,7 @@ var DATE_FORMATS = { GGGG: longEraGetter }; -var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|m+|s+|a|Z|G+|w+))(.*)/, +var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|m+|s+|a|Z|G+|w+))([\s\S]*)/, NUMBER_STRING = /^-?\d+$/; /** diff --git a/test/ng/filter/filtersSpec.js b/test/ng/filter/filtersSpec.js index bdd9b81a2417..dafb22b98863 100644 --- a/test/ng/filter/filtersSpec.js +++ b/test/ng/filter/filtersSpec.js @@ -504,6 +504,11 @@ describe('filters', function() { expect(date(morning, 'yy/xxx')).toEqual('10/xxx'); }); + it('should allow newlines in format', function() { + expect(date(midnight, 'EEE\nMMM d\'\n\'yy/xxx\n')). + toEqual('Fri\nSep 3\n10/xxx\n'); + }); + it('should support various iso8061 date strings with timezone as input', function() { var format = 'yyyy-MM-dd ss'; From 2dd35ac451cc76c9c561f36c5adeeb72920ed5bc Mon Sep 17 00:00:00 2001 From: Ash Searle Date: Sun, 12 Mar 2017 17:06:30 +0000 Subject: [PATCH 2/2] fix(date filter): handle newlines in format string Closes #15794 --- src/ng/filter/filters.js | 2 ++ test/ng/filter/filtersSpec.js | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index 3e97e7cebd15..3f83895f74c2 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -534,6 +534,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+ * `"h 'in the morning'"`). In order to output a single quote, escape it - i.e., two single quotes in a sequence * (e.g. `"h 'o''clock'"`). * + * Any other characters in the `format` string will be output as-is. + * * @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or * number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its * shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is diff --git a/test/ng/filter/filtersSpec.js b/test/ng/filter/filtersSpec.js index dafb22b98863..8e3a54a0b2df 100644 --- a/test/ng/filter/filtersSpec.js +++ b/test/ng/filter/filtersSpec.js @@ -505,8 +505,7 @@ describe('filters', function() { }); it('should allow newlines in format', function() { - expect(date(midnight, 'EEE\nMMM d\'\n\'yy/xxx\n')). - toEqual('Fri\nSep 3\n10/xxx\n'); + expect(date(midnight, 'EEE\nMMM d\'\n\'yy/xxx\n')).toEqual('Fri\nSep 3\n10/xxx\n'); }); it('should support various iso8061 date strings with timezone as input', function() {