fix(07.1-02): allowlist UTC, Etc/UTC, GMT in IANA validator
This commit is contained in:
parent
f55b937af9
commit
660d039b80
1 changed files with 7 additions and 0 deletions
|
|
@ -17,8 +17,15 @@ function getDefaultTimezone(): string {
|
|||
return process.env.DEFAULT_TIMEZONE || 'UTC';
|
||||
}
|
||||
|
||||
// Node's Intl.supportedValuesOf('timeZone') returns canonical IANA zones only —
|
||||
// it omits 'UTC', 'Etc/UTC', 'GMT', and the entire Etc/* alias namespace, even
|
||||
// though those are valid for Postgres AT TIME ZONE and JS Date methods. The
|
||||
// migration default is 'UTC', so the validator must accept it explicitly.
|
||||
const EXTRA_ALLOWED_TIMEZONES = new Set(['UTC', 'Etc/UTC', 'GMT', 'Etc/GMT']);
|
||||
|
||||
function isValidIanaTimezone(tz: unknown): tz is string {
|
||||
if (typeof tz !== 'string' || tz.length === 0 || tz.length > 64) return false;
|
||||
if (EXTRA_ALLOWED_TIMEZONES.has(tz)) return true;
|
||||
try {
|
||||
const zones = Intl.supportedValuesOf('timeZone');
|
||||
return zones.includes(tz);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue