Bug 76893

Summary: Implement value sanitization algorithm for type=datetime
Product: WebKit Reporter: Kent Tamura <tkent>
Component: FormsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: kaustubh.ra, ksakamoto, mifenton, webkit.review.bot
Priority: P2 Keywords: WebExposed
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 37024    
Attachments:
Description Flags
Patch
none
Patch 2 none

Description Kent Tamura 2012-01-23 20:46:02 PST
http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#date-and-time-state-(type=datetime)
> The value sanitization algorithm is as follows: If the value of the element is a valid global date and time string, then adjust the time so that the value represents the same point in time but expressed in the UTC time zone as a valid normalized forced-UTC global date and time string, otherwise, set it to the empty string instead.
Comment 1 Kunihiko Sakamoto 2012-10-18 19:31:53 PDT
Created attachment 169537 [details]
Patch
Comment 2 Kent Tamura 2012-10-18 20:28:48 PDT
Comment on attachment 169537 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=169537&action=review


> LayoutTests/fast/forms/datetime/datetime-value-sanitization-expected.txt:9
> +PASS input.value = "2009-09-07T16:49:00Z"; input.value is "2009-09-07T16:49Z"
> +PASS input.value = "2009-09-07T16:49:00.000Z"; input.value is "2009-09-07T16:49Z"

Can you preserve trailing zeros of the input datetime values?

If we do so, we should do:
 - Add "SecondFormat m_preferredSecondForamt;" and "SecondFormat preferredSecondFormat() const" to DateComponents
 - m_preferredSecondFormat is updated in DateComponents::parseTime
 - DateTimeInputType::sanitizeValue calls date.toString(date.preferredSecondFormat)

> LayoutTests/fast/forms/datetime/datetime-value-sanitization.html:1
> +<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<!DOCTYPE html>

is enough.

> LayoutTests/fast/forms/datetime/datetime-value-sanitization.html:8
> +<p id="description"></p>
> +<div id="console"></div>

Please remove them.  They are unnecessary nowadays.

> LayoutTests/fast/forms/datetime/datetime-value-sanitization.html:15
> +// Valid values

Such labels are useful for test results too.
So please print it by debug('Valid values');

> LayoutTests/fast/forms/datetime/datetime-value-sanitization.html:16
> +shouldBe('input.value = "2009-09-07T16:49Z"; input.value', '"2009-09-07T16:49Z"');

should be:
  shouldBeEqualToString('input.value ...', '2009-09-07T16:49Z');
to avoid ugly nested quotes.
Comment 3 Kunihiko Sakamoto 2012-10-18 20:49:53 PDT
Comment on attachment 169537 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=169537&action=review

>> LayoutTests/fast/forms/datetime/datetime-value-sanitization-expected.txt:9
>> +PASS input.value = "2009-09-07T16:49:00.000Z"; input.value is "2009-09-07T16:49Z"
> 
> Can you preserve trailing zeros of the input datetime values?
> 
> If we do so, we should do:
>  - Add "SecondFormat m_preferredSecondForamt;" and "SecondFormat preferredSecondFormat() const" to DateComponents
>  - m_preferredSecondFormat is updated in DateComponents::parseTime
>  - DateTimeInputType::sanitizeValue calls date.toString(date.preferredSecondFormat)

The spec says that normalized value is the shortest possible representation of the given time.
http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#valid-normalized-forced-utc-global-date-and-time-string
Is there a good reason for keeping the second format of the input?
Comment 4 Kent Tamura 2012-10-18 20:56:18 PDT
Comment on attachment 169537 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=169537&action=review

>>> LayoutTests/fast/forms/datetime/datetime-value-sanitization-expected.txt:9
>>> +PASS input.value = "2009-09-07T16:49:00.000Z"; input.value is "2009-09-07T16:49Z"
>> 
>> Can you preserve trailing zeros of the input datetime values?
>> 
>> If we do so, we should do:
>>  - Add "SecondFormat m_preferredSecondForamt;" and "SecondFormat preferredSecondFormat() const" to DateComponents
>>  - m_preferredSecondFormat is updated in DateComponents::parseTime
>>  - DateTimeInputType::sanitizeValue calls date.toString(date.preferredSecondFormat)
> 
> The spec says that normalized value is the shortest possible representation of the given time.
> http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#valid-normalized-forced-utc-global-date-and-time-string
> Is there a good reason for keeping the second format of the input?

Oh, I see.  It is a standard behavior.
So, the C++ part of your patch is ok.
Comment 5 Kunihiko Sakamoto 2012-10-18 21:16:23 PDT
Created attachment 169541 [details]
Patch 2
Comment 6 Kunihiko Sakamoto 2012-10-18 21:17:14 PDT
Updated the test. Please take another look.
Comment 7 Kent Tamura 2012-10-18 21:40:36 PDT
Comment on attachment 169541 [details]
Patch 2

ok
Comment 8 WebKit Review Bot 2012-10-18 21:45:53 PDT
Comment on attachment 169541 [details]
Patch 2

Clearing flags on attachment: 169541

Committed r131853: <http://trac.webkit.org/changeset/131853>
Comment 9 WebKit Review Bot 2012-10-18 21:45:57 PDT
All reviewed patches have been landed.  Closing bug.