date-vir 9.1.0 → 9.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,9 +7,11 @@ const knownTimezones = new Set(allTimezoneNames);
7
7
  * Caches the result of the {@link Info.isValidIANAZone} fallback. That call constructs an
8
8
  * `Intl.DateTimeFormat` every time (~30µs), so memoizing it keeps repeated checks of the same
9
9
  * string (a legacy alias or an invalid value) cheap. Only strings outside the typed
10
- * {@link knownTimezones} set ever land here, so the cache stays small in practice.
10
+ * {@link knownTimezones} set ever land here. The cache is capped to keep untrusted input from
11
+ * growing it without bound.
11
12
  */
12
13
  const ianaValidityCache = new Map();
14
+ const maxIanaValidityCacheEntries = 1000;
13
15
  /**
14
16
  * Checks that the given timezone is valid.
15
17
  *
@@ -28,6 +30,12 @@ export function isValidTimezone(raw) {
28
30
  return cached;
29
31
  }
30
32
  const isValid = Info.isValidIANAZone(raw);
33
+ if (ianaValidityCache.size >= maxIanaValidityCacheEntries) {
34
+ const oldestEntry = ianaValidityCache.keys().next();
35
+ if (!oldestEntry.done) {
36
+ ianaValidityCache.delete(oldestEntry.value);
37
+ }
38
+ }
31
39
  ianaValidityCache.set(raw, isValid);
32
40
  return isValid;
33
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-vir",
3
- "version": "9.1.0",
3
+ "version": "9.1.1",
4
4
  "description": "Easy and explicit dates and times.",
5
5
  "keywords": [
6
6
  "date",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@augment-vir/assert": "^32.2.1",
39
39
  "@augment-vir/common": "^32.2.1",
40
- "@date-vir/duration": "^9.1.0",
40
+ "@date-vir/duration": "^9.1.1",
41
41
  "@types/luxon": "^3.7.3",
42
42
  "luxon": "^3.7.2",
43
43
  "object-shape-tester": "^6.14.1",