From: Tim Wood Date: Wed, 21 Mar 2012 17:01:53 +0000 (-0700) Subject: Making ISO8601 parsing regex stricter X-Git-Tag: 1.5.1~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3b1fb95e9ecb7025eecf5d91be6490852db5ade;p=thirdparty%2Fmoment.git Making ISO8601 parsing regex stricter #215 --- diff --git a/moment.js b/moment.js index 3b2a46bf7..5392e30a6 100644 --- a/moment.js +++ b/moment.js @@ -18,7 +18,7 @@ timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g, tokenCharacters = /(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g, inputCharacters = /(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi, - isoRegex = /\d{4}.\d\d.\d\d(T(\d\d(.\d\d(.\d\d)?)?)?([\+\-]\d\d:?\d\d)?)?/, + isoRegex = /^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d)?)?)?([\+\-]\d\d:?\d\d)?)?/, isoFormat = 'YYYY-MM-DDTHH:mm:ssZ', isoTimes = [ ['HH:mm:ss', /T\d\d:\d\d:\d\d/], diff --git a/test/moment/create.js b/test/moment/create.js index 7e9afa040..3a68557e9 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -47,6 +47,13 @@ exports.create = { test.done(); }, + "string from Date.toString" : function(test) { + test.expect(1); + var str = (new Date()).toString(); + test.equal(moment(str).toString(), str, "Parsing a string from Date.prototype.toString should match moment.fn.toString"); + test.done(); + }, + "string without format - json" : function(test) { test.expect(5); test.equal(moment("Date(1325132654000)").valueOf(), 1325132654000, "Date(1325132654000)");