From aa94ce3b86632ad05301530a2213099da73a3dc0 Mon Sep 17 00:00:00 2001 From: christopherthielen Date: Thu, 20 Nov 2014 19:57:35 -0600 Subject: [PATCH] fix($urlMatcherFactory): make date type fn check .is before running Closes #1564 --- src/urlMatcherFactory.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index 9114c3c48..a16e728c5 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -588,8 +588,9 @@ function $UrlMatcherFactory() { }, date: { encode: function (val) { - return [ - val.getFullYear(), + if (!this.is(val)) + return undefined; + return [ val.getFullYear(), ('0' + (val.getMonth() + 1)).slice(-2), ('0' + val.getDate()).slice(-2) ].join("-"); @@ -600,7 +601,7 @@ function $UrlMatcherFactory() { return match ? new Date(match[1], match[2] - 1, match[3]) : undefined; }, is: function(val) { return val instanceof Date && !isNaN(val.valueOf()); }, - equals: function (a, b) { return a.toISOString() === b.toISOString(); }, + equals: function (a, b) { return this.is(a) && this.is(b) && a.toISOString() === b.toISOString(); }, pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/, capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/ },