Skip to content

Commit 757975c

Browse files
committed
test(dateParser): test for reserved symbols
1 parent d55ae4c commit 757975c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/helpers/date-parser.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,10 @@ angular.module('mgcrea.ngStrap.helpers.dateParser', [])
278278
for(var i = 0; i < dateElements.length; i++) {
279279
re = re.split('${' + i + '}').join('(' + regExpMap[dateElements[i]] + ')');
280280
}
281-
re = escapeReservedSymbols(re);
282281

283282
return new RegExp('^' + re + '$', ['i']);
284283
}
285284

286-
function escapeReservedSymbols(text) {
287-
return text.replace(/\//g, '[\\/]').replace('/-/g', '[-]').replace(/\./g, '[.]').replace(/\\s/g, '[\\s]');
288-
}
289-
290285
function setMapForFormat(format) {
291286
var re = buildDateAbstractRegex(format);
292287
return buildDateParseValuesMap(re);

src/helpers/test/date-parser.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,5 +423,19 @@ describe('dateParser', function() {
423423
]);
424424
});
425425

426+
describe('format with reserved symbols', function() {
427+
beforeEach(function() {
428+
parser = $dateParser({format: 'EEEE.d.y'});
429+
});
430+
431+
it('should validate date with reserved symbols', function() {
432+
expect(parser.isValid('Wednesday.01/2014')).toBe(true);
433+
});
434+
435+
generateTestCasesForParsing([
436+
{val: 'Wednesday.01/2014', expect: new Date(2014, 0, 1, 0, 0, 0), reason: 'format string with escaped literal'}
437+
]);
438+
});
439+
426440
});
427441
});

0 commit comments

Comments
 (0)