Skip to content

[FIX] sap.ui.core.format.DateFormat: escape calendar week pattern#4453

Open
martindglaser wants to merge 1 commit into
UI5:masterfrom
martindglaser:fix/dateformat-escape-calendar-week
Open

[FIX] sap.ui.core.format.DateFormat: escape calendar week pattern#4453
martindglaser wants to merge 1 commit into
UI5:masterfrom
martindglaser:fix/dateformat-escape-calendar-week

Conversation

@martindglaser

Copy link
Copy Markdown
Contributor

Summary

When parsing the wide/narrow week-in-year field, DateFormat turns the localized calendar-week text from LocaleData#getCalendarWeek into a RegExp without escaping its literal part:

sPart = oFormat.oLocaleData.getCalendarWeek(...);   // e.g. hu narrow: "{0}. NH"
sPart = sPart.replace("{0}", "([0-9]+)");
var rWeekNumber = new RegExp(sPart);                 // "([0-9]+). NH"

@kgogov

kgogov commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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,
Konstantin

@1110101

1110101 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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.
@martindglaser
martindglaser force-pushed the fix/dateformat-escape-calendar-week branch from 09c0912 to d55666e Compare July 18, 2026 02:00
@martindglaser

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants