Closed Bug 1003246 Opened 10 years ago Closed 10 years ago

Invalid assertion in nsDateTimeFormatMac

Categories

(Core :: Internationalization, defect)

All
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla32

People

(Reporter: mt, Assigned: mt)

Details

Attachments

(1 file)

The MAC date formatter has an invalid assertion when forcing the use of 24H times.  This pulls the date format string from the OS date formatter and does `tr 'ha' 'HA'`.  These strings usually contain repeated instances of 'H' characters[1], but the code asserts if it finds more than one.  This line[2] should be removed or changed to:

    NS_ASSERTION(replaceCount < 0 || replaceCount > 2, "Unexpected number of \"h\" occurrences");

[1] http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
[2] http://dxr.mozilla.org/mozilla-central/source/intl/locale/src/mac/nsDateTimeFormatMac.cpp#191
Looks like there are cases where 'h' or 'a' don't appear at all, e.g., [1].  These places shouldn't trigger the assertion, so inverting the logic (!), I get:

    NS_ASSERTION(replaceCount <= 2, "Unexpected number of \"h\" occurrences");

[1] http://dxr.mozilla.org/mozilla-central/source/security/manager/ssl/src/nsNSSCertValidity.cpp
Assertion changes only.
Attachment #8414608 - Flags: review?(jshin1987)
Comment on attachment 8414608 [details] [diff] [review]
0001-Bug-1003246-Loosening-assertion-to-allow-for-other-v.patch

jshin no longer works at Mozilla. Asking jwatt as he wrote the code.
Attachment #8414608 - Flags: review?(jshin1987) → review?(jwatt)
The "Fixed Formats" section of:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html

says that the format is defined by the Unicode Technical Standard #35:

http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns

And that says:

  Characters may be used multiple times. For example, if y is used
  for the year, 'yy' might produce '99', whereas 'yyyy' produces '1999'.

So allowing "hh" clearly seems correct.

Above the quoted text there is also an example showing "yyyyy.MMMM.dd GGG hh:mm aaa" resolving to "01996.July.10 AD 12:08 PM", which seems to make clear that multiple "a"s are allowed.
That said, it's probably a good idea to not support more than two "h"s or more than one "a".
Attachment #8414608 - Flags: review?(jwatt) → review+
Keywords: checkin-needed
Can you please run this through Try if you haven't already done so? And post a link here if you did :)

Thanks!
Keywords: checkin-needed
It's not done yet, but I'm prepared to call that a success.
Assignee: nobody → martin.thomson
Status: NEW → ASSIGNED
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/608d04865f00
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla32
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: