You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by "Thiago H. de Paula Figueiredo (JIRA)" <ji...@apache.org> on 2014/01/03 20:03:59 UTC

[jira] [Commented] (TAP5-1998) DateField does not validate dates properly

    [ https://issues.apache.org/jira/browse/TAP5-1998?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13861786#comment-13861786 ] 

Thiago H. de Paula Figueiredo commented on TAP5-1998:
-----------------------------------------------------

Hi, Barry!

I really cannot figure how we could use DateFormat.parse(String, ParsePosition) here. What ParsePosition value would we use? I have absolutely no idea.

I'll commit a fix that adds the SymbolConstants.LENIENT_DATE_FORMAT (tapestry.lenient-date-format) symbol with a default value of false. In addition, DateField gets a 'lenient' parameter that takes the symbol as its default value.

Cheers!

Thiago

> DateField does not validate dates properly
> ------------------------------------------
>
>                 Key: TAP5-1998
>                 URL: https://issues.apache.org/jira/browse/TAP5-1998
>             Project: Tapestry 5
>          Issue Type: Improvement
>          Components: tapestry-core
>    Affects Versions: 5.4
>            Reporter: Barry Books
>            Assignee: Thiago H. de Paula Figueiredo
>            Priority: Minor
>              Labels: month-of-tapestry, patch
>
> Due to the way the Java DateFormat class works there are 2 cases that allow invalid dates threw the DateField component.
> 1. By default date parsing is lenient. This means dates such as 00/01/2000 are converted to 12/01/1999 and passed thru. There is no way for the application to know this has happened.
> 2. The DateFormat class ignores trailing characters. This means an input of 01/01/200- will result in a date of 01/01/200 again there is no way for the application to know this has happened.
> It's possible to work around both these issues but I think the workarounds are not obvious and in practice difficult to implement. To work around the first problem you can pass a DateFormat with lenient set to false. The service that converts Strings to DateFormat does not do this and it does not seem possible to override it so all the DateFormats much be created in Java code. The second issue can be resolved by providing a regexp expression to validate the date. For some date formats  such as MM/dd/yyyy this is pretty easy but other date formats are complex and it's difficult to come up with a correct regular expression.
> So I would like to propose changing DateField to set lenient to false and use parse(source,pos) instead of paste(source). This change is not strictly backward compatible and a parameter could be added that allows the old behavior. My guess is there are not many people depending on the existing behavior  since it really allows invalid dates to be silently input.
> I have a patch that I can contribute.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)