[FIX] sap.ui.core.format.DateFormat: escape calendar week pattern#4453
[FIX] sap.ui.core.format.DateFormat: escape calendar week pattern#4453martindglaser wants to merge 1 commit into
Conversation
|
Hello @martindglaser, Thank you for creating this PR — much appreciated! 🙌 I've created internal incident DINC0976856 to track this. Colleagues responsible for this module will look it up soon, and I'll keep the status updated here. Regards, |
|
Hi, thanks for your contribution! Im part of the team which is responsible for DateFormat and took a quick look before the weekend. Could you please add a new or extend an existing unit test for this? |
When parsing the wide/narrow week-in-year field ("ww"/"w..."), the localized
calendar-week text from LocaleData#getCalendarWeek was turned into a RegExp
without escaping its literal part. Regex metacharacters in that text were thus
interpreted instead of matched literally - e.g. the "." in the Hungarian narrow
pattern "{0}. NH" acts as a wildcard, so "5x NH" is wrongly accepted. A pattern
containing an unbalanced bracket would even throw a SyntaxError.
Escape the literal segments (splitting on the "{0}" placeholder) before building
the RegExp, using sap/base/strings/escapeRegExp. Extend the weekInYear QUnit
test to cover the Hungarian narrow pattern.
09c0912 to
d55666e
Compare
|
Thanks @1110101! I've extended the existing "format and parse weekInYear pattern" test in DateFormat.qunit.js to cover the Hungarian narrow calendar-week pattern ("{0}. NH"): it formats the narrow week, parses it back, and asserts that a corrupted separator (". NH" → "X NH") is now rejected — this case parses successfully before the fix (the . acts as a wildcard) and returns null after it. Amended into the same commit. Let me know if you'd prefer it split into a dedicated test or extended to the wide pattern as well. |
Summary
When parsing the wide/narrow week-in-year field,
DateFormatturns the localized calendar-week text fromLocaleData#getCalendarWeekinto aRegExpwithout escaping its literal part: