diff --git a/lib/__tests__/cookieJar.spec.ts b/lib/__tests__/cookieJar.spec.ts index bbfb3af9..2407293b 100644 --- a/lib/__tests__/cookieJar.spec.ts +++ b/lib/__tests__/cookieJar.spec.ts @@ -134,7 +134,7 @@ describe('CookieJar', () => { cookieJar.setCookie('=b', 'http://example.com/index.html', { loose: false, }), - ).rejects.toThrowError('Cookie failed to parse') + ).rejects.toThrow('Cookie failed to parse') }) it('should not default to loose: true when using map', () => { @@ -254,7 +254,7 @@ describe('CookieJar', () => { 'a=b; Domain=fooxample.com; Path=/', 'http://example.com/index.html', ), - ).rejects.toThrowError( + ).rejects.toThrow( "Cookie not in this host's domain. Cookie:fooxample.com Request:example.com", ) }) @@ -266,7 +266,7 @@ describe('CookieJar', () => { 'a=b; Domain=www.example.com; Path=/', 'http://example.com/index.html', ), - ).rejects.toThrowError( + ).rejects.toThrow( "Cookie not in this host's domain. Cookie:www.example.com Request:example.com", ) }) @@ -301,7 +301,7 @@ describe('CookieJar', () => { 'http://example.com/index.html', { http: false }, ), - ).rejects.toThrowError("Cookie is HttpOnly and this isn't an HTTP API") + ).rejects.toThrow("Cookie is HttpOnly and this isn't an HTTP API") }) it('should not fail when using an httpOnly cookie when using a non-HTTP API', async () => { @@ -1069,7 +1069,7 @@ describe('setCookie errors', () => { const cookieJar = new CookieJar() await expect( cookieJar.setCookie('i=9; Domain=kyoto.jp; Path=/', 'http://kyoto.jp'), - ).rejects.toThrowError('Cookie has domain set to a public suffix') + ).rejects.toThrow('Cookie has domain set to a public suffix') }) it('should throw an error if domains do not match', async () => { @@ -1079,7 +1079,7 @@ describe('setCookie errors', () => { 'j=10; Domain=google.com; Path=/', 'http://google.ca', ), - ).rejects.toThrowError( + ).rejects.toThrow( `Cookie not in this host's domain. Cookie:google.com Request:google.ca`, ) }) @@ -1097,7 +1097,7 @@ describe('setCookie errors', () => { 'http://example.ca', { http: false }, ), - ).rejects.toThrowError("old Cookie is HttpOnly and this isn't an HTTP API") + ).rejects.toThrow("old Cookie is HttpOnly and this isn't an HTTP API") const cookies = await cookieJar.getCookies('http://example.ca', { http: true, @@ -1149,7 +1149,7 @@ it('should fix issue #132', async () => { await expect( // @ts-expect-error test case is explicitly testing invalid input cookieJar.setCookie({ key: 'x', value: 'y' }, 'http://example.com/'), - ).rejects.toThrowError( + ).rejects.toThrow( 'First argument to setCookie must be a Cookie object or string', ) }) @@ -1186,9 +1186,9 @@ it('should fix issue #145 - missing 2nd url parameter', async () => { it('should fix issue #197 - CookieJar().setCookie throws an error when empty cookie is passed', async () => { const cookieJar = new CookieJar() - await expect( - cookieJar.setCookie('', 'https://google.com'), - ).rejects.toThrowError('Cookie failed to parse') + await expect(cookieJar.setCookie('', 'https://google.com')).rejects.toThrow( + 'Cookie failed to parse', + ) }) it('should fix issue #282 - Prototype pollution when setting a cookie with the domain __proto__', () => { diff --git a/lib/__tests__/cookiePrefixes.spec.ts b/lib/__tests__/cookiePrefixes.spec.ts index 770f53a9..6b7d9d39 100644 --- a/lib/__tests__/cookiePrefixes.spec.ts +++ b/lib/__tests__/cookiePrefixes.spec.ts @@ -132,7 +132,7 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => { insecureUrl, {}, ), - ).rejects.toThrowError( + ).rejects.toThrow( 'Cookie has __Secure prefix but Secure attribute is not set', ) }) @@ -161,7 +161,7 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => { secureUrl, {}, ), - ).rejects.toThrowError( + ).rejects.toThrow( `Cookie has __Host prefix but either Secure or HostOnly attribute is not set or Path is not '/'`, ) }) diff --git a/lib/__tests__/jarSerialization.spec.ts b/lib/__tests__/jarSerialization.spec.ts index 734548df..1ad8b249 100644 --- a/lib/__tests__/jarSerialization.spec.ts +++ b/lib/__tests__/jarSerialization.spec.ts @@ -65,7 +65,7 @@ describe('cookieJar serialization', () => { store.synchronous = true const jar = new CookieJar(store) - expect(() => jar.toJSON()).toThrowError( + expect(() => jar.toJSON()).toThrow( 'getAllCookies is not implemented (therefore jar cannot be serialized)', ) }) @@ -76,7 +76,7 @@ describe('cookieJar serialization', () => { const store = new MemoryCookieStore() store.synchronous = false const jar = new CookieJar(store) - expect(() => jar.toJSON()).toThrowError( + expect(() => jar.toJSON()).toThrow( 'CookieJar store is not synchronous; use async API instead.', ) }) @@ -165,7 +165,7 @@ describe('cookieJar serialization', () => { it('should raise an error when attempting to synchronously clone to an async store', () => { const newStore = new MemoryCookieStore() newStore.synchronous = false - expect(() => jar.cloneSync(newStore)).toThrowError( + expect(() => jar.cloneSync(newStore)).toThrow( 'CookieJar clone destination store is not synchronous; use async API instead.', ) }) diff --git a/lib/__tests__/removeAll.spec.ts b/lib/__tests__/removeAll.spec.ts index c8c72102..8d203cb5 100644 --- a/lib/__tests__/removeAll.spec.ts +++ b/lib/__tests__/removeAll.spec.ts @@ -79,7 +79,7 @@ describe('store removeAllCookies API', () => { _removeCookie.call(store, domain, path, key, callback) }) - await expect(jar.removeAllCookies()).rejects.toThrowError( + await expect(jar.removeAllCookies()).rejects.toThrow( 'something happened 1', ) diff --git a/lib/__tests__/sameSite.spec.ts b/lib/__tests__/sameSite.spec.ts index 8259f8ae..65c325cd 100644 --- a/lib/__tests__/sameSite.spec.ts +++ b/lib/__tests__/sameSite.spec.ts @@ -139,7 +139,7 @@ describe('Same-Site Cookies', function () { it('should not allow strict cookie to be set', async () => { await expect( cookieJar.setCookie(strict, url, { sameSiteContext: 'none' }), - ).rejects.toThrowError( + ).rejects.toThrow( 'Cookie is SameSite but this is a cross-origin request', ) }) @@ -147,7 +147,7 @@ describe('Same-Site Cookies', function () { it('should not allow lax cookie to be set', async () => { await expect( cookieJar.setCookie(lax, url, { sameSiteContext: 'none' }), - ).rejects.toThrowError( + ).rejects.toThrow( 'Cookie is SameSite but this is a cross-origin request', ) }) diff --git a/lib/cookie/cookie.ts b/lib/cookie/cookie.ts index 24c85601..031fcf71 100644 --- a/lib/cookie/cookie.ts +++ b/lib/cookie/cookie.ts @@ -76,7 +76,7 @@ function parseCookiePair( if (looseMode) { if (firstEq === 0) { // '=' is immediately at start - cookiePair = cookiePair.substr(1) + cookiePair = cookiePair.substring(1) firstEq = cookiePair.indexOf('=') // might still need to split on '=' } } else { @@ -284,8 +284,7 @@ function fromJSON(str: unknown): Cookie | undefined { if (typeof str === 'string') { try { obj = JSON.parse(str) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (e) { + } catch { return undefined } } else { diff --git a/lib/cookie/cookieJar.ts b/lib/cookie/cookieJar.ts index 5933208a..80976094 100644 --- a/lib/cookie/cookieJar.ts +++ b/lib/cookie/cookieJar.ts @@ -662,7 +662,7 @@ export class CookieJar { ): Promise { return this.putCookie(newCookie).then( () => cb?.(null), - (error: Error) => cb?.(error), + (error: unknown) => cb?.(error as Error), ) } } diff --git a/lib/cookie/domainMatch.ts b/lib/cookie/domainMatch.ts index dd071eea..c73f58f7 100644 --- a/lib/cookie/domainMatch.ts +++ b/lib/cookie/domainMatch.ts @@ -98,7 +98,7 @@ export function domainMatch( /* " * The last character of the string that is not included in the * domain string is a %x2E (".") character." */ - if (_str.substr(idx - 1, 1) !== '.') { + if (_str.substring(idx - 1, idx) !== '.') { return false // doesn't align on "." } diff --git a/package-lock.json b/package-lock.json index 45b03656..9bb486f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1585,9 +1585,9 @@ } }, "node_modules/@types/node": { - "version": "16.18.106", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.106.tgz", - "integrity": "sha512-YTgQUcpdXRc7iiEMutkkXl9WUx5lGUCVYvnfRg9CV+IA4l9epctEhCTbaw4KgzXaKYv8emvFJkEM65+MkNUhsQ==", + "version": "16.18.108", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.108.tgz", + "integrity": "sha512-fj42LD82fSv6yN9C6Q4dzS+hujHj+pTv0IpRR3kI20fnYeS0ytBpjFO9OjmDowSPPt4lNKN46JLaKbCyP+BW2A==", "dev": true }, "node_modules/@types/stack-utils": { @@ -1612,16 +1612,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.0.1.tgz", - "integrity": "sha512-5g3Y7GDFsJAnY4Yhvk8sZtFfV6YNF2caLzjrRPUBzewjPCaj0yokePB4LJSobyCzGMzjZZYFbwuzbfDHlimXbQ==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.4.0.tgz", + "integrity": "sha512-rg8LGdv7ri3oAlenMACk9e+AR4wUV0yrrG+XKsGKOK0EVgeEDqurkXMPILG2836fW4ibokTB5v4b6Z9+GYQDEw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.0.1", - "@typescript-eslint/type-utils": "8.0.1", - "@typescript-eslint/utils": "8.0.1", - "@typescript-eslint/visitor-keys": "8.0.1", + "@typescript-eslint/scope-manager": "8.4.0", + "@typescript-eslint/type-utils": "8.4.0", + "@typescript-eslint/utils": "8.4.0", + "@typescript-eslint/visitor-keys": "8.4.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -1645,15 +1645,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.0.1.tgz", - "integrity": "sha512-5IgYJ9EO/12pOUwiBKFkpU7rS3IU21mtXzB81TNwq2xEybcmAZrE9qwDtsb5uQd9aVO9o0fdabFyAmKveXyujg==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.4.0.tgz", + "integrity": "sha512-NHgWmKSgJk5K9N16GIhQ4jSobBoJwrmURaLErad0qlLjrpP5bECYg+wxVTGlGZmJbU03jj/dfnb6V9bw+5icsA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.0.1", - "@typescript-eslint/types": "8.0.1", - "@typescript-eslint/typescript-estree": "8.0.1", - "@typescript-eslint/visitor-keys": "8.0.1", + "@typescript-eslint/scope-manager": "8.4.0", + "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/typescript-estree": "8.4.0", + "@typescript-eslint/visitor-keys": "8.4.0", "debug": "^4.3.4" }, "engines": { @@ -1673,13 +1673,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.0.1.tgz", - "integrity": "sha512-NpixInP5dm7uukMiRyiHjRKkom5RIFA4dfiHvalanD2cF0CLUuQqxfg8PtEUo9yqJI2bBhF+pcSafqnG3UBnRQ==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.4.0.tgz", + "integrity": "sha512-n2jFxLeY0JmKfUqy3P70rs6vdoPjHK8P/w+zJcV3fk0b0BwRXC/zxRTEnAsgYT7MwdQDt/ZEbtdzdVC+hcpF0A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.0.1", - "@typescript-eslint/visitor-keys": "8.0.1" + "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/visitor-keys": "8.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1690,13 +1690,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.0.1.tgz", - "integrity": "sha512-+/UT25MWvXeDX9YaHv1IS6KI1fiuTto43WprE7pgSMswHbn1Jm9GEM4Txp+X74ifOWV8emu2AWcbLhpJAvD5Ng==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.4.0.tgz", + "integrity": "sha512-pu2PAmNrl9KX6TtirVOrbLPLwDmASpZhK/XU7WvoKoCUkdtq9zF7qQ7gna0GBZFN0hci0vHaSusiL2WpsQk37A==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.0.1", - "@typescript-eslint/utils": "8.0.1", + "@typescript-eslint/typescript-estree": "8.4.0", + "@typescript-eslint/utils": "8.4.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -1714,9 +1714,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.0.1.tgz", - "integrity": "sha512-PpqTVT3yCA/bIgJ12czBuE3iBlM3g4inRSC5J0QOdQFAn07TYrYEQBBKgXH1lQpglup+Zy6c1fxuwTk4MTNKIw==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.4.0.tgz", + "integrity": "sha512-T1RB3KQdskh9t3v/qv7niK6P8yvn7ja1mS7QK7XfRVL6wtZ8/mFs/FHf4fKvTA0rKnqnYxl/uHFNbnEt0phgbw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1727,15 +1727,15 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.0.1.tgz", - "integrity": "sha512-8V9hriRvZQXPWU3bbiUV4Epo7EvgM6RTs+sUmxp5G//dBGy402S7Fx0W0QkB2fb4obCF8SInoUzvTYtc3bkb5w==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.4.0.tgz", + "integrity": "sha512-kJ2OIP4dQw5gdI4uXsaxUZHRwWAGpREJ9Zq6D5L0BweyOrWsL6Sz0YcAZGWhvKnH7fm1J5YFE1JrQL0c9dd53A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.0.1", - "@typescript-eslint/visitor-keys": "8.0.1", + "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/visitor-keys": "8.4.0", "debug": "^4.3.4", - "globby": "^11.1.0", + "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", @@ -1791,15 +1791,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.0.1.tgz", - "integrity": "sha512-CBFR0G0sCt0+fzfnKaciu9IBsKvEKYwN9UZ+eeogK1fYHg4Qxk1yf/wLQkLXlq8wbU2dFlgAesxt8Gi76E8RTA==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.4.0.tgz", + "integrity": "sha512-swULW8n1IKLjRAgciCkTCafyTHHfwVQFt8DovmaF69sKbOxTSFMmIZaSHjqO9i/RV0wIblaawhzvtva8Nmm7lQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.0.1", - "@typescript-eslint/types": "8.0.1", - "@typescript-eslint/typescript-estree": "8.0.1" + "@typescript-eslint/scope-manager": "8.4.0", + "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/typescript-estree": "8.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1813,12 +1813,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.0.1.tgz", - "integrity": "sha512-W5E+o0UfUcK5EgchLZsyVWqARmsM7v54/qEq6PY3YI5arkgmCzHiuk0zKSJJbm71V0xdRna4BGomkCTXz2/LkQ==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.4.0.tgz", + "integrity": "sha512-zTQD6WLNTre1hj5wp09nBIDiOc2U5r/qmzo7wxPn4ZgAjHql09EofqhF9WF+fZHzL5aCyaIpPcT2hyxl73kr9A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.0.1", + "@typescript-eslint/types": "8.4.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1982,15 +1982,6 @@ "sprintf-js": "~1.0.2" } }, - "node_modules/array-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/async": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", @@ -2479,18 +2470,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, - "dependencies": { - "path-type": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -3239,26 +3218,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/globby": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", - "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, - "dependencies": { - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.2.9", - "ignore": "^5.2.0", - "merge2": "^1.4.1", - "slash": "^3.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -4585,15 +4544,6 @@ "node": ">= 0.8.0" } }, - "node_modules/path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/picocolors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", @@ -5407,14 +5357,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.0.1.tgz", - "integrity": "sha512-V3Y+MdfhawxEjE16dWpb7/IOgeXnLwAEEkS7v8oDqNcR1oYlqWhGH/iHqHdKVdpWme1VPZ0SoywXAkCqawj2eQ==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.4.0.tgz", + "integrity": "sha512-67qoc3zQZe3CAkO0ua17+7aCLI0dU+sSQd1eKPGq06QE4rfQjstVXR6woHO5qQvGUa550NfGckT4tzh3b3c8Pw==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.0.1", - "@typescript-eslint/parser": "8.0.1", - "@typescript-eslint/utils": "8.0.1" + "@typescript-eslint/eslint-plugin": "8.4.0", + "@typescript-eslint/parser": "8.4.0", + "@typescript-eslint/utils": "8.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0"