Uploaded image for project: 'Commons Validator'
  1. Commons Validator
  2. VALIDATOR-316

The GenericTypeValidator.formateDate method handles the strict mode check inproperly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Abandoned
    • 1.3.1 Release, 1.4.0 Release
    • None
    • Framework

    Description

      When the strict mode is on, the GenericTypeValidator.formatDate(String value, String datePattern, boolean strict) method tests if the value.length() equals the datePattern.length().

      This comparison does not take into consideration that the datePattern may contain single quotes to avoid some plain text being interpreted as pattern letters. For example, as described in SimpleDateFormat, "Wed, Jul 4, '01" is suitable for pattern "EEE, MMM d, ''yy" while the two strings have different length.

      On the other hand, the length comparison doesn't work in some Locales. In Locale.CHINESE, the datePattern part "MMM" matches "三月" (two Chinese characters, literally "the third month"), while in Locale.JAPANESE, the datePattern part "EEE" matches "日" (single Japanese Kanji/Chinese character, literally "Sun" or "Day").

      Even though the examples above are rarely used in production, the length comparison is still not acceptable. Setting lenient to true, or comparison between the original text and the formatted text from the result Date using the same pattern is better.

      Attachments

        Activity

          People

            Unassigned Unassigned
            captmjc Michael J Chane
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: