From f8b4574250172cb5d765d7f3b205192fcbb3d483 Mon Sep 17 00:00:00 2001 From: "ulan@chromium.org" Date: Wed, 13 Jun 2012 09:10:37 +0000 Subject: [PATCH] Return an error when parsing invalid dates where a number immediately follows a word. BUG=53209,126448 TEST=mjsunit/date-parse.js R=rossberg@chromium.org Review URL: https://chromiumcodereview.appspot.com/10541138 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11791 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/dateparser-inl.h | 3 +++ test/mjsunit/date-parse.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/dateparser-inl.h b/src/dateparser-inl.h index 32f0f9ea8f..a5c7143bdd 100644 --- a/src/dateparser-inl.h +++ b/src/dateparser-inl.h @@ -148,6 +148,9 @@ bool DateParser::Parse(Vector str, } else { // Garbage words are illegal if a number has been read. if (has_read_number) return false; + // The first number has to be separated from garbage words by + // whitespace or other separators. + if (scanner.Peek().IsNumber()) return false; } } else if (token.IsAsciiSign() && (tz.IsUTC() || !time.IsEmpty())) { // Parse UTC offset (only after UTC or time). diff --git a/test/mjsunit/date-parse.js b/test/mjsunit/date-parse.js index b46e39ab61..cb4a951c7a 100644 --- a/test/mjsunit/date-parse.js +++ b/test/mjsunit/date-parse.js @@ -287,6 +287,9 @@ for (var i = 0; i < 24 * 365 * 100; i += 150) { var testCasesNegative = [ 'May 25 2008 1:30 (PM)) UTC', // Bad unmatched ')' after number. 'May 25 2008 1:30( )AM (PM)', // + 'a1', // Issue 126448, 53209. + 'nasfdjklsfjoaifg1', + 'x_2', 'May 25 2008 AAA (GMT)']; // Unknown word after number. testCasesNegative.forEach(function (s) {