[webkit-changes] cvs commit: LayoutTests/fast/js
date-parse-comments-test-expected.txt date-parse-comments-test.html
Darin
darin at opensource.apple.com
Sat Oct 8 21:45:31 PDT 2005
darin 05/10/08 21:45:30
Modified: . ChangeLog
kjs date_object.cpp
. ChangeLog
Added: fast/js date-parse-comments-test-expected.txt
date-parse-comments-test.html
Log:
JavaScriptCore:
Reviewed by Geoff.
Tweaked and landed by Darin.
- fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=5266
Support parenthesized comments in Date.parse()
* kjs/date_object.cpp:
(KJS::skipSpacesAndComments): Take a pointer, and advance it past spaces,
and also past anything enclosed in parentheses.
(KJS::KRFCDate_parseDate): Use skipSpacesAndComments wherever we formerly had
code to skip spaces.
LayoutTests:
- added a test for http://bugzilla.opendarwin.org/show_bug.cgi?id=5266
Support parenthesized comments in Date.parse()
* fast/js/date-parse-comments-test-expected.txt: Added.
* fast/js/date-parse-comments-test.html: Added.
Revision Changes Path
1.857 +14 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.856
retrieving revision 1.857
diff -u -r1.856 -r1.857
--- ChangeLog 9 Oct 2005 04:24:58 -0000 1.856
+++ ChangeLog 9 Oct 2005 04:45:26 -0000 1.857
@@ -1,3 +1,17 @@
+2005-10-08 Mitz Pettel <opendarwin.org at mitzpettel.com>
+
+ Reviewed by Geoff.
+ Tweaked and landed by Darin.
+
+ - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=5266
+ Support parenthesized comments in Date.parse()
+
+ * kjs/date_object.cpp:
+ (KJS::skipSpacesAndComments): Take a pointer, and advance it past spaces,
+ and also past anything enclosed in parentheses.
+ (KJS::KRFCDate_parseDate): Use skipSpacesAndComments wherever we formerly had
+ code to skip spaces.
+
2005-10-08 Justin Haygood <justin at xiondigital.net>
Reviewed, tweaked, and landed by Darin.
1.60 +37 -28 JavaScriptCore/kjs/date_object.cpp
Index: date_object.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/date_object.cpp,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- date_object.cpp 4 Oct 2005 01:43:58 -0000 1.59
+++ date_object.cpp 9 Oct 2005 04:45:28 -0000 1.60
@@ -1031,6 +1031,23 @@
return (mktime(t) + utcOffset) * 1000.0 + ms + yearOffset;
}
+inline static void skipSpacesAndComments(const char *&s)
+{
+ int nesting = 0;
+ char ch;
+ while ((ch = *s)) {
+ if (!isspace(ch)) {
+ if (ch == '(')
+ nesting++;
+ else if (ch == ')' && nesting > 0)
+ nesting--;
+ else if (nesting == 0)
+ break;
+ }
+ s++;
+ }
+}
+
// returns 0-11 (Jan-Dec); -1 on failure
static int findMonth(const char *monthStr)
{
@@ -1083,19 +1100,16 @@
bool have_time = false;
// Skip leading space
- while(isspace(*dateString))
- dateString++;
+ skipSpacesAndComments(dateString);
const char *wordStart = dateString;
// Check contents of first words if not number
- while(*dateString && !isdigit(*dateString))
- {
- if ( isspace(*dateString) && dateString - wordStart >= 3 )
- {
- month = findMonth(wordStart);
- while(isspace(*dateString))
- dateString++;
- wordStart = dateString;
+ while (*dateString && !isdigit(*dateString)) {
+ if (isspace(*dateString) || *dateString == '(') {
+ if (dateString - wordStart >= 3)
+ month = findMonth(wordStart);
+ skipSpacesAndComments(dateString);
+ wordStart = dateString;
}
else
dateString++;
@@ -1106,8 +1120,7 @@
// TODO: emit warning about dubious format found
}
- while(isspace(*dateString))
- dateString++;
+ skipSpacesAndComments(dateString);
if (!*dateString)
return invalidDate;
@@ -1162,8 +1175,7 @@
if (*dateString == '-')
dateString++;
- while(isspace(*dateString))
- dateString++;
+ skipSpacesAndComments(dateString);
if (*dateString == ',')
dateString++;
@@ -1174,7 +1186,7 @@
if (month == -1)
return invalidDate;
- while(*dateString && (*dateString != '-') && !isspace(*dateString))
+ while (*dateString && (*dateString != '-') && !isspace(*dateString))
dateString++;
if (!*dateString)
@@ -1206,8 +1218,11 @@
year = -1;
else
return invalidDate;
- } else // in the normal case (we parsed the year), advance to the next number
+ } else {
+ // in the normal case (we parsed the year), advance to the next number
dateString = ++newPosStr;
+ skipSpacesAndComments(dateString);
+ }
hour = strtol(dateString, &newPosStr, 10);
@@ -1254,8 +1269,7 @@
return invalidDate;
}
- while(isspace(*dateString))
- dateString++;
+ skipSpacesAndComments(dateString);
if (strncasecmp(dateString, "AM", 2) == 0) {
if (hour > 12)
@@ -1263,16 +1277,14 @@
if (hour == 12)
hour = 0;
dateString += 2;
- while (isspace(*dateString))
- dateString++;
+ skipSpacesAndComments(dateString);
} else if (strncasecmp(dateString, "PM", 2) == 0) {
if (hour > 12)
return invalidDate;
if (hour != 12)
hour += 12;
dateString += 2;
- while (isspace(*dateString))
- dateString++;
+ skipSpacesAndComments(dateString);
}
}
} else {
@@ -1288,8 +1300,7 @@
have_tz = true;
}
- while (isspace(*dateString))
- ++dateString;
+ skipSpacesAndComments(dateString);
if (strncasecmp(dateString, "GMT", 3) == 0) {
dateString += 3;
@@ -1327,8 +1338,7 @@
}
}
- while(isspace(*dateString))
- dateString++;
+ skipSpacesAndComments(dateString);
if ( *dateString && year == -1 ) {
year = strtol(dateString, &newPosStr, 10);
@@ -1337,8 +1347,7 @@
dateString = newPosStr;
}
- while (isspace(*dateString))
- dateString++;
+ skipSpacesAndComments(dateString);
// Trailing garbage
if (*dateString != '\0')
1.26 +8 -0 LayoutTests/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/LayoutTests/ChangeLog,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- ChangeLog 9 Oct 2005 04:36:57 -0000 1.25
+++ ChangeLog 9 Oct 2005 04:45:29 -0000 1.26
@@ -1,3 +1,11 @@
+2005-10-08 Mitz Pettel <opendarwin.org at mitzpettel.com>
+
+ - added a test for http://bugzilla.opendarwin.org/show_bug.cgi?id=5266
+ Support parenthesized comments in Date.parse()
+
+ * fast/js/date-parse-comments-test-expected.txt: Added.
+ * fast/js/date-parse-comments-test.html: Added.
+
2005-10-08 Alexey Proskuryakov <ap at nypop.com>
- added a test case for XSLT charset support
1.1 LayoutTests/fast/js/date-parse-comments-test-expected.txt
Index: date-parse-comments-test-expected.txt
===================================================================
Testing complete. No failures.
1.1 LayoutTests/fast/js/date-parse-comments-test.html
Index: date-parse-comments-test.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>test of JavaScript date parsing (comments in parentheses)</title>
</head>
<body>
<script type="text/javascript">
if (window.layoutTestController)
layoutTestController.dumpAsText();
// --------
// Helper functions.
function call(functionName, parameter)
{
try {
result = eval(functionName + "(parameter)");
} catch (e) {
result = "exception";
}
return result;
}
// --------
// Run tests.
var failureCount = 0;
function test(functionName, parameter, desiredResult)
{
var result = call(functionName, parameter);
if (result != desiredResult && !(isNaN(result) && isNaN(desiredResult))) {
var s = "called " + functionName + " on " + parameter + " and got " + result + " instead of " + desiredResult;
document.writeln("<p>" + s + "</p>");
failureCount += 1;
return 0;
}
return 1;
}
function testDateParse(date, numericResult)
{
if (test("Date.parse", date, numericResult)) {
test("Date.parse", date.toUpperCase(), numericResult);
test("Date.parse", date.toLowerCase(), numericResult);
}
}
var o = Date.parse(" Dec 25 1995 1:30 ") - Date.parse(" Dec 25 1995 1:30 GMT ");
testDateParse("Dec ((27) 26 (24)) 25 1995 1:30 PM UTC", 819898200000);
testDateParse("Dec 25 1995 1:30 PM UTC (", 819898200000);
testDateParse("Dec 25 1995 1:30 (PM)) UTC", NaN);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) GMT (EST)", 819849600000);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996)", 819849600000 + o);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) GMT (EST)", 819855000000);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40)", 819855000000 + o);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 ", 819855000000 + o);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 AM (1:40 PM) GMT (EST)", 819855000000);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 AM (1:40 PM)", 819855000000 + o);
testDateParse("Dec 25 1995 1:30( )AM (PM)", NaN);
testDateParse("Dec 25 1995 1:30 AM (PM)", 819855000000 + o);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40) GMT (PST)", 819898200000);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40)", 819898200000 + o);
testDateParse('(Nov) Dec (24) 25 (26) 13:30 (13:40) 1995 (1996)', 819898200000 + o);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40) ", 819898200000 + o);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) PM (AM) GMT (PST)", 819898200000);
testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) PM (AM)", 819898200000 + o);
testDateParse("Dec 25 1995 1:30(AM)PM", NaN);
testDateParse("Dec 25 1995 1:30 (AM)PM ", 819898200000 + o);
testDateParse("Dec 25 1995 (PDT)UTC(PST)", 819849600000);
testDateParse("Dec 25 1995 (PDT)UT(PST)", 819849600000);
testDateParse("Dec 25 1995 (UTC)PST(GMT)", 819878400000);
testDateParse("Dec 25 1995 (UTC)PDT(GMT)", 819874800000);
testDateParse("Dec 25 1995 1:30 (PDT)UTC(PST)", 819855000000);
testDateParse("Dec 25 1995 1:30 (PDT)UT(PST)", 819855000000);
testDateParse("Dec 25 1995 1:30 (UTC)PST(GMT)", 819883800000);
testDateParse("Dec 25 1995 1:30 (UTC)PDT(GMT)", 819880200000);
testDateParse("Dec 25 1995 1:30 (AM) PM (PST) UTC", 819898200000);
testDateParse("Dec 25 1995 1:30 PM (AM) (PST) UT", 819898200000);
testDateParse("Dec 25 1995 1:30 PM (AM) (UTC) PST", 819927000000);
testDateParse("Dec 25 1995 1:30 (AM) PM PDT (UTC)", 819923400000);
testDateParse("Dec 25 1995 XXX (GMT)", NaN);
testDateParse("Dec 25 1995 1:30 XXX (GMT)", NaN);
testDateParse("Dec 25 1995 1:30 U(TC)", NaN);
testDateParse("Dec 25 1995 1:30 V(UTC)", NaN);
testDateParse("Dec 25 1995 1:30 (UTC)W", NaN);
testDateParse("Dec 25 1995 1:30 (GMT)X", NaN);
testDateParse("Dec 25 1995 0:30 (PM) GMT", 819851400000);
testDateParse("Dec 25 1995 (1)0:30 AM GMT", 819851400000);
testDateParse("Dec 25 1995 (1)0:30 PM GMT", 819894600000);
testDateParse("Anf(Dec) 25 1995 GMT", NaN);
testDateParse("(Sat) Wed (Nov) Dec (Nov) 25 1995 1:30 GMT", 819855000000);
testDateParse("Wed (comment 1) (comment 2) Dec 25 1995 1:30 GMT", 819855000000);
testDateParse("Wed(comment 1) (comment 2) Dec 25 1995 1:30 GMT", 819855000000);
testDateParse("We(comment 1) (comment 2) Dec 25 1995 1:30 GMT", 819855000000);
// --------
// Summarize.
var failuresMessage;
if (failureCount) {
failuresMessage = failureCount + " tests failed.";
} else {
failuresMessage = "No failures.";
}
document.writeln("<p>Testing complete. " + failuresMessage + "</p>");
// --------
</script>
</body>
</html>
More information about the webkit-changes
mailing list