Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-1998

DateField does not validate dates properly

    Details

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              thiagohp Thiago H. de Paula Figueiredo
              Reporter:
              trsvax Barry Books
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: