Reviewers: Lasse Reichstein,
Message:
I discussed quite a bit with lasse about how to best support Date.parse on
timestamps only. The problem is that the spec is not specific on this. I
states
that one should accept strings that conform to 15.9.1.15, but leaves out
how to
handle timestamp only values. There is a number of solutions:
The date part defaults to today
The date part defaults to 2000-01-01
The date part defaults to 1970-01-01 (probably best solution - but we might
break compatibility with other browsers)
Description:
Correct issue 696 with Date.parse returning a value when called on a non
date
string.
The error was introduced in revision 4557 where support was added for
ES5 date time format strings. Because there was no check for a valid
year a random string starting with a non-digit character would be
parsed.
This change disallows ES5 formatted dates where there is no date
fraction (i.e., with only a timestamp). Since none of the other
browsers support Date.parse on only timestamps I have disabled this
totally instead of just correcting the parser.
Please review this at http://codereview.chromium.org/2017005/show
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M src/dateparser.cc
Index: src/dateparser.cc
===================================================================
--- src/dateparser.cc (revision 4607)
+++ src/dateparser.cc (working copy)
@@ -33,16 +33,12 @@
namespace internal {
bool DateParser::DayComposer::Write(FixedArray* output) {
- // Set year to 0 by default.
- if (index_ < 1) {
- comp_[index_++] = 1;
- }
+ if (index_ < 1) return false;
+ // Day and month defaults to 1.
+ while (index_ < kSize) {
+ comp_[index_++] = 1;
+ }
- // Day and month defaults to 1.
- while (index_ < kSize) {
- comp_[index_++] = 1;
- }
-
int year = 0; // Default year is 0 (=> 2000) for KJS compatibility.
int month = kNone;
int day = kNone;
@@ -62,7 +58,6 @@
}
} else {
month = named_month_;
- if (index_ < 1) return false;
if (index_ == 1) {
// MD or DM
day = comp_[0];
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev