You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Barry Books (JIRA)" <ji...@apache.org> on 2012/08/30 14:59:07 UTC

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

Barry Books created TAP5-1998:
---------------------------------

             Summary: 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
            Priority: Minor


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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira