Skip to content

Commit 39f5f9d

Browse files
committed
Treat latin alphabets as reserved token in formatWithoutLocale
1 parent 90bdb8b commit 39f5f9d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/datetime/formatWithoutLocale.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ test("single quotes", () => {
2020
).toEqual(`'24 1 2'`);
2121
});
2222

23+
test("unknown token", () => {
24+
// pattern 'G' is for era name, not supported.
25+
expect(() => {
26+
formatWithoutLocale(Temporal.PlainDate.from(target), "G");
27+
}).toThrow();
28+
});
29+
2330
test("year", () => {
2431
const ok = [
2532
Temporal.ZonedDateTime.from(target),

src/datetime/formatWithoutLocale.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export interface FormatWithoutLocaleOptions {
304304
*
305305
* Characters between two single quotes (`'`) in the format are escaped.
306306
* Two consecutive single quotes (`''`) in the format always represents one single quote (`'`).
307+
* Letters `A` to `Z` and `a` to `z` are reserved for use as pattern characters, unless they are escaped.
307308
*
308309
* Available field patterns are subset of date field symbols in Unicode CLDR,
309310
* see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table for details.
@@ -363,7 +364,7 @@ export function formatWithoutLocale(
363364
"Unbalanced single quotes. Use single quotes for escaping and two single quotes to represent actual single quote.",
364365
);
365366
}
366-
const regex = /''|'(''|[^'])+'|y+|M+|d+|h+|H+|m+|s+|S+|VV|x+|X+/g;
367+
const regex = /''|'(''|[^'])+'|(([a-zA-Z])\3*)/g;
367368
return format.replace(regex, (match) => {
368369
if (match === `''`) {
369370
return `'`;

0 commit comments

Comments
 (0)