Repository: sinonjs/fake-timers
Pull request #473 (2023-07-09 23:57:52)

Bump tough-cookie from 4.1.2 to 4.1.3
Bumps [tough-cookie](https://github.com/salesforce/tough-cookie) from 4.1.2 to 4.1.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/salesforce/tough-cookie/releases">tough-cookie's releases</a>.</em></p>
<blockquote>
<h2>4.1.3</h2>
<p>Security fix for Prototype Pollution discovery in <a href="https://redirect.github.com/salesforce/tough-cookie/issues/282">#282</a>. This is a minor release, although output from the <code>inspect</code> utility is affected by this change, we felt this change was important enough to be pushed into the next patch.</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/salesforce/tough-cookie/commit/4ff4d29f6cefd279a412b8d62a21142ebd410b36"><code>4ff4d29</code></a> 4.1.3 release preparation, update the package and lib/version to 4.1.3. (<a href="https://redirect.github.com/salesforce/tough-cookie/issues/284">#284</a>)</li>
<li><a href="https://github.com/salesforce/tough-cookie/commit/12d474791bb856004e858fdb1c47b7608d09cf6e"><code>12d4747</code></a> Prevent prototype pollution in cookie memstore (<a href="https://redirect.github.com/salesforce/tough-cookie/issues/283">#283</a>)</li>
<li><a href="https://github.com/salesforce/tough-cookie/commit/f06b72d1d447f33dfa6222c0a3c0c5e063558248"><code>f06b72d</code></a> Fix documentation for store.findCookies, missing allowSpecialUseDomain proper...</li>
<li>See full diff in <a href="https://github.com/salesforce/tough-cookie/compare/v4.1.2...v4.1.3">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tough-cookie&package-manager=npm_and_yarn&previous-version=4.1.2&new-version=4.1.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/sinonjs/fake-timers/network/alerts).

</details>

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/sinonjs/fake-timers/pull/473?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs) Report
Patch and project coverage have no change.
> Comparison is base [(`2fc8324`)](https://app.codecov.io/gh/sinonjs/fake-timers/commit/2fc83240262c8f0e8690e75d9d18dca1fd61b952?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs) 95.66% compared to head [(`0e2908d`)](https://app.codecov.io/gh/sinonjs/fake-timers/pull/473?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs) 95.66%.

> :exclamation: Current head 0e2908d differs from pull request most recent head 870c1f1. Consider uploading reports for the commit 870c1f1 to get more accurate results

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #473   +/-   ##
=======================================
  Coverage   95.66%   95.66%           
=======================================
  Files           2        2           
  Lines         669      669           
=======================================
  Hits          640      640           
  Misses         29       29           
```

| Flag | Coverage Δ | |
|---|---|---|
| unit | `95.66% <ø> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs#carryforward-flags-in-the-pull-request-comment) to find out more.



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/sinonjs/fake-timers/pull/473?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sinonjs).


Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 61fdd58..48233f5 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -112,7 +112,7 @@ jobs:
 
         strategy:
             matrix:
-                node-version: [14, 16, 18, 19]
+                node-version: [16, 18, 20]
 
         steps:
             - uses: actions/checkout@v3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 940100e..5cac950 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,3 @@
-
 11.0.0 / 2023-06-12
 ==================
   * Re-release 10.2.0 as a new major version as mocking Node "timers" module broke some setups
diff --git a/package-lock.json b/package-lock.json
index 10d7350..3db10c6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6770,9 +6770,9 @@
       }
     },
     "node_modules/tough-cookie": {
-      "version": "4.1.2",
-      "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz",
-      "integrity": "sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==",
+      "version": "4.1.3",
+      "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz",
+      "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==",
       "dev": true,
       "dependencies": {
         "psl": "^1.1.33",
@@ -7279,9 +7279,9 @@
       }
     },
     "node_modules/word-wrap": {
-      "version": "1.2.3",
-      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
-      "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
+      "version": "1.2.4",
+      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
+      "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
       "dev": true,
       "engines": {
         "node": ">=0.10.0"
@@ -12845,9 +12845,9 @@
       }
     },
     "tough-cookie": {
-      "version": "4.1.2",
-      "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz",
-      "integrity": "sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==",
+      "version": "4.1.3",
+      "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz",
+      "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==",
       "dev": true,
       "requires": {
         "psl": "^1.1.33",
@@ -13267,9 +13267,9 @@
       }
     },
     "word-wrap": {
-      "version": "1.2.3",
-      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
-      "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
+      "version": "1.2.4",
+      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
+      "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
       "dev": true
     },
     "workerpool": {
diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js
index f5129e5..31371c5 100644
--- a/src/fake-timers-src.js
+++ b/src/fake-timers-src.js
@@ -143,8 +143,6 @@ if (typeof require === "function" && typeof module === "object") {
  * @returns {FakeTimers}
  */
 function withGlobal(_global) {
-    const userAgent = _global.navigator && _global.navigator.userAgent;
-    const isRunningInIE = userAgent && userAgent.indexOf("MSIE ") > -1;
     const maxTimeout = Math.pow(2, 31) - 1; //see https://heycam.github.io/webidl/#abstract-opdef-converttoint
     const idCounterStart = 1e12; // arbitrarily large number to avoid collisions with native timer IDs
     const NOOP = function () {
@@ -186,29 +184,12 @@ function withGlobal(_global) {
         typeof _global.cancelIdleCallback === "function";
     const setImmediatePresent =
         _global.setImmediate && typeof _global.setImmediate === "function";
-
-    // Make properties writable in IE, as per
-    // https://www.adequatelygood.com/Replacing-setTimeout-Globally.html
-    /* eslint-disable no-self-assign */
-    if (isRunningInIE) {
-        _global.setTimeout = _global.setTimeout;
-        _global.clearTimeout = _global.clearTimeout;
-        _global.setInterval = _global.setInterval;
-        _global.clearInterval = _global.clearInterval;
-        _global.Date = _global.Date;
-    }
-
-    // setImmediate is not a standard function
-    // avoid adding the prop to the window object if not present
-    if (setImmediatePresent) {
-        _global.setImmediate = _global.setImmediate;
-        _global.clearImmediate = _global.clearImmediate;
-    }
-    /* eslint-enable no-self-assign */
+    const intlPresent = _global.Intl && typeof _global.Intl === "object";
 
     _global.clearTimeout(timeoutResult);
 
     const NativeDate = _global.Date;
+    const NativeIntl = _global.Intl;
     let uniqueTimerId = idCounterStart;
 
     /**
@@ -500,6 +481,40 @@ function withGlobal(_global) {
         return mirrorDateProperties(ClockDate, NativeDate);
     }
 
+    //eslint-disable-next-line jsdoc/require-jsdoc
+    function createIntl() {
+        const ClockIntl = { ...NativeIntl };
+
+        ClockIntl.DateTimeFormat = function (...args) {
+            const realFormatter = new NativeIntl.DateTimeFormat(...args);
+            const formatter = {};
+
+            ["formatRange", "formatRangeToParts", "resolvedOptions"].forEach(
+                (method) => {
+                    formatter[method] =
+                        realFormatter[method].bind(realFormatter);
+                }
+            );
+
+            ["format", "formatToParts"].forEach((method) => {
+                formatter[method] = function (date) {
+                    return realFormatter[method](date || ClockIntl.clock.now);
+                };
+            });
+
+            return formatter;
+        };
+
+        ClockIntl.DateTimeFormat.prototype = Object.create(
+            NativeIntl.DateTimeFormat.prototype
+        );
+
+        ClockIntl.DateTimeFormat.supportedLocalesOf =
+            NativeIntl.DateTimeFormat.supportedLocalesOf;
+
+        return ClockIntl;
+    }
+
     //eslint-disable-next-line jsdoc/require-jsdoc
     function enqueueJob(clock, job) {
         // enqueues a microtick-deferred task - ecma262/#sec-enqueuejob
@@ -934,6 +949,8 @@ function withGlobal(_global) {
         if (method === "Date") {
             const date = mirrorDateProperties(clock[method], target[method]);
             target[method] = date;
+        } else if (method === "Intl") {
+            target[method] = clock[method];
         } else if (method === "performance") {
             const originalPerfDescriptor = Object.getOwnPropertyDescriptor(
                 target,
@@ -988,6 +1005,7 @@ function withGlobal(_global) {
      * @property {setInterval} setInterval
      * @property {clearInterval} clearInterval
      * @property {Date} Date
+     * @property {Intl} Intl
      * @property {SetImmediate=} setImmediate
      * @property {function(NodeImmediate): void=} clearImmediate
      * @property {function(number[]):number[]=} hrtime
@@ -1046,6 +1064,10 @@ function withGlobal(_global) {
         timers.cancelIdleCallback = _global.cancelIdleCallback;
     }
 
+    if (intlPresent) {
+        timers.Intl = _global.Intl;
+    }
+
     const originalSetTimeout = _global.setImmediate || _global.setTimeout;
 
     /**
@@ -1124,6 +1146,11 @@ function withGlobal(_global) {
             };
         }
 
+        if (intlPresent) {
+            clock.Intl = createIntl();
+            clock.Intl.clock = clock;
+        }
+
         clock.requestIdleCallback = function requestIdleCallback(
             func,
             timeout


Test patch:
diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js
index 5ecce05..c0ae9af 100644
--- a/test/fake-timers-test.js
+++ b/test/fake-timers-test.js
@@ -5179,3 +5179,125 @@ describe("Node Timer: ref(), unref(),hasRef()", function () {
         clock.uninstall();
     });
 });
+
+describe("Intl API", function () {
+    /**
+     * Tester function to check if the globally hijacked Intl object is plugging into the faked Clock
+     *
+     * @param {string} ianaTimeZone - IANA time zone name
+     * @param {number} timestamp - UNIX timestamp
+     * @returns {boolean}
+     */
+    function isFirstOfMonth(ianaTimeZone, timestamp) {
+        return (
+            new Intl.DateTimeFormat(undefined, { timeZone: ianaTimeZone })
+                .formatToParts(timestamp)
+                .find((part) => part.type === "day").value === "1"
+        );
+    }
+
+    let clock;
+
+    before(function () {
+        clock = FakeTimers.install();
+    });
+
+    after(function () {
+        clock.uninstall();
+    });
+
+    it("Executes formatRange like normal", function () {
+        const start = new Date(Date.UTC(2020, 0, 1, 0, 0));
+        const end = new Date(Date.UTC(2020, 0, 1, 0, 1));
+        const options = {
+            timeZone: "UTC",
+            hour12: false,
+            hour: "numeric",
+            minute: "numeric",
+        };
+        assert.equals(
+            new Intl.DateTimeFormat("en-GB", options).formatRange(start, end),
+            "00:00–00:01"
+        );
+    });
+
+    it("Executes formatRangeToParts like normal", function () {
+        const start = new Date(Date.UTC(2020, 0, 1, 0, 0));
+        const end = new Date(Date.UTC(2020, 0, 1, 0, 1));
+        const options = {
+            timeZone: "UTC",
+            hour12: false,
+            hour: "numeric",
+            minute: "numeric",
+        };
+        assert.equals(
+            new Intl.DateTimeFormat("en-GB", options).formatRangeToParts(
+                start,
+                end
+            ),
+            [
+                { type: "hour", value: "00", source: "startRange" },
+                { type: "literal", value: ":", source: "startRange" },
+                { type: "minute", value: "00", source: "startRange" },
+                { type: "literal", value: "–", source: "shared" },
+                { type: "hour", value: "00", source: "endRange" },
+                { type: "literal", value: ":", source: "endRange" },
+                { type: "minute", value: "01", source: "endRange" },
+            ]
+        );
+    });
+
+    it("Executes resolvedOptions like normal", function () {
+        const options = {
+            timeZone: "UTC",
+            hour12: false,
+            hour: "2-digit",
+            minute: "2-digit",
+        };
+        assert.equals(
+            new Intl.DateTimeFormat("en-GB", options).resolvedOptions(),
+            {
+                locale: "en-GB",
+                calendar: "gregory",
+                numberingSystem: "latn",
+                timeZone: "UTC",
+                hour12: false,
+                hourCycle: "h23",
+                hour: "2-digit",
+                minute: "2-digit",
+            }
+        );
+    });
+
+    it("formatToParts via isFirstOfMonth -> Returns true when passed a timestamp argument that is first of the month", function () {
+        // June 1 04:00 UTC - Toronto is June 1 00:00
+        assert.isTrue(
+            isFirstOfMonth("America/Toronto", Date.UTC(2022, 5, 1, 4))
+        );
+    });
+
+    it("formatToParts via isFirstOfMonth -> Returns false when passed a timestamp argument that is not first of the month", function () {
+        // June 1 00:00 UTC - Toronto is May 31 20:00
+        assert.isFalse(isFirstOfMonth("America/Toronto", Date.UTC(2022, 5, 1)));
+    });
+
+    it("formatToParts via isFirstOfMonth -> Returns true when passed no timestamp and system time is first of the month", function () {
+        // June 1 04:00 UTC - Toronto is June 1 00:00
+        clock.now = Date.UTC(2022, 5, 1, 4);
+        assert.isTrue(isFirstOfMonth("America/Toronto"));
+    });
+
+    it("formatToParts via isFirstOfMonth -> Returns false when passed no timestamp and system time is not first of the month", function () {
+        // June 1 00:00 UTC - Toronto is May 31 20:00
+        clock.now = Date.UTC(2022, 5, 1);
+        assert.isFalse(isFirstOfMonth("America/Toronto"));
+    });
+
+    it("Executes supportedLocalesOf like normal", function () {
+        assert.equals(
+            Intl.DateTimeFormat.supportedLocalesOf(),
+            //eslint-disable-next-line no-underscore-dangle
+            clock._Intl.DateTimeFormat.supportedLocalesOf()
+        );
+    });
+});