Skip to content

Commit

Permalink
Merge pull request #323 from salesforce/bump-deps
Browse files Browse the repository at this point in the history
Bump dependencies.
  • Loading branch information
colincasey authored Dec 8, 2023
2 parents 0b8a77e + eff6df6 commit c95413c
Show file tree
Hide file tree
Showing 9 changed files with 2,120 additions and 1,609 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/strict",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
Expand All @@ -13,6 +13,8 @@
},
"reportUnusedDisableDirectives": true,
"rules": {
// Causes a lot of errors - will address separately
"@typescript-eslint/no-invalid-void-type": "off",
"max-lines": ["warn", 500]
}
}
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ updates:
update-types:
- "version-update:semver-major"
- "version-update:semver-minor"
# As a library, upgrading TypeScript and using new language features would
# be a breaking change for users who have not yet upgraded their TS version
- dependency-name: "typescript"
10 changes: 4 additions & 6 deletions lib/__tests__/cookieJar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,8 @@ describe('CookieJar', () => {
)
},
async asyncStyle() {
cookieHeaders = await cookieJar.getSetCookieStrings(
'http://example.com',
)
cookieHeaders =
await cookieJar.getSetCookieStrings('http://example.com')
},
syncStyle() {
cookieHeaders =
Expand Down Expand Up @@ -891,9 +890,8 @@ describe('CookieJar', () => {
})

it('be able to get the set-cookie header strings for http://example.com', async () => {
cookieHeaders = await cookieJar.getSetCookieStrings(
'http://example.com',
)
cookieHeaders =
await cookieJar.getSetCookieStrings('http://example.com')
expect(cookieHeaders).toEqual([
'a=1; Domain=example.com; Path=/',
'b=2; Domain=example.com; Path=/; HttpOnly',
Expand Down
59 changes: 23 additions & 36 deletions lib/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('Cookie.parse', () => {
},
// way too many semicolons followed by non-semicolon
{
input: `foo=bar${';'.repeat(65535)} domain=example.com`,
input: `foo=bar<REPEAT ;> domain=example.com`,
output: {
key: 'foo',
value: 'bar',
Expand All @@ -323,7 +323,7 @@ describe('Cookie.parse', () => {
},
// way too many spaces - large one doesn't parse
{
input: `x${' '.repeat(65535)}x`,
input: `x<REPEAT \u0020>x`, // '\u0020' === ' '
output: undefined,
},
// same-site - lax
Expand Down Expand Up @@ -397,19 +397,23 @@ describe('Cookie.parse', () => {
output: null,
},
])('Cookie.parse("$input")', (testCase) => {
const { input, output } = testCase
const parseOptions = testCase.parseOptions || {}
// Repeating the character in the input makes the jest output obnoxiously long, so instead we
// use a template pattern and replace it.
const input = testCase.input?.replace(/<REPEAT (.)>/, (_, char: string) =>
char.repeat(65535),
)
const { output, parseOptions = {}, assertValidateReturns } = testCase

const value = input === undefined ? undefined : input.valueOf()
const cookie = Cookie.parse(value as string, parseOptions)
if (output !== undefined) {
expect(cookie).toEqual(expect.objectContaining(output))
expect(cookie).toEqual(output && expect.objectContaining(output))
} else {
expect(cookie).toBe(output)
}

if (cookie && typeof testCase.assertValidateReturns === 'boolean') {
expect(cookie.validate()).toBe(testCase.assertValidateReturns)
if (cookie && typeof assertValidateReturns === 'boolean') {
expect(cookie.validate()).toBe(assertValidateReturns)
}
})

Expand All @@ -420,30 +424,32 @@ describe('Cookie.parse', () => {
// - way too many spaces with value (strict mode)
it.each([
{
shortVersion: 'x x',
longVersion: `x${' '.repeat(65535)}x`,
prefix: 'x',
postfix: 'x',
},
{
shortVersion: 'x x',
longVersion: `x${' '.repeat(65535)}x`,
prefix: 'x',
postfix: 'x',
parseOptions: { loose: true },
},
{
shortVersion: 'x =x',
longVersion: `x${' '.repeat(65535)}=x`,
prefix: 'x',
postfix: '=x',
},
{
shortVersion: 'x =x',
longVersion: `x${' '.repeat(65535)}=x`,
prefix: 'x',
postfix: '=x',
parseOptions: { loose: true },
},
])(
'Cookie.parse("$shortVersion") should not take significantly longer to run than Cookie.parse("$longVersion")',
({ shortVersion, longVersion, parseOptions = {} }) => {
'Cookie.parse("$prefix $postfix") should not take significantly longer to run than Cookie.parse("$prefix<TOO MANY SPACES>$postfix")',
({ prefix, postfix, parseOptions = {} }) => {
const shortVersion = `${prefix} ${postfix}`
const startShortVersionParse = performance.now()
Cookie.parse(shortVersion, parseOptions)
const endShortVersionParse = performance.now()

const longVersion = `${prefix}${' '.repeat(65535)}${postfix}`
const startLongVersionParse = performance.now()
Cookie.parse(longVersion, parseOptions)
const endLongVersionParse = performance.now()
Expand All @@ -455,22 +461,3 @@ describe('Cookie.parse', () => {
},
)
})

// way too many spaces - takes about the same time for each
it('should parse a long cookie string with spaces in roughly the same amount of time as one with short spaces', () => {
const longCookie = `x${' '.repeat(65535)}x`
const shortCookie = `x x`

const startLongCookieParse = performance.now()
Cookie.parse(longCookie)
const endLongCookieParse = performance.now()

const startShortCookieParse = performance.now()
Cookie.parse(shortCookie)
const endShortCookieParse = performance.now()

const ratio =
(endLongCookieParse - startLongCookieParse) /
(endShortCookieParse - startShortCookieParse)
expect(ratio).toBeLessThan(250) // if broken this ratio goes 2000-4000x higher
})
2 changes: 1 addition & 1 deletion lib/cookie/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function parse(
return c
}

function fromJSON(str: string | SerializedCookie | null | undefined | unknown) {
function fromJSON(str: unknown) {
if (!str || validators.isEmptyString(str)) {
return null
}
Expand Down
23 changes: 8 additions & 15 deletions lib/cookie/cookieJar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,10 @@ export class CookieJar {
options: SetCookieOptions,
callback: Callback<Cookie | undefined>,
): void
setCookie(cookie: string | Cookie, url: string): Promise<Cookie | undefined>
setCookie(
cookie: string | Cookie,
url: string,
options: SetCookieOptions,
options?: SetCookieOptions,
): Promise<Cookie | undefined>
setCookie(
cookie: string | Cookie,
Expand Down Expand Up @@ -509,10 +508,9 @@ export class CookieJar {
options: GetCookiesOptions | undefined,
callback: Callback<Cookie[]>,
): void
getCookies(url: string): Promise<Cookie[]>
getCookies(
url: string,
options: GetCookiesOptions | undefined,
options?: GetCookiesOptions | undefined,
): Promise<Cookie[]>
getCookies(
url: string,
Expand Down Expand Up @@ -618,7 +616,6 @@ export class CookieJar {
// non-RFC: allow retention of expired cookies by choice
const expiryTime = c.expiryTime()
if (expireCheck && expiryTime && expiryTime <= now) {
// eslint-disable-next-line @typescript-eslint/no-empty-function
store.removeCookie(c.domain, c.path, c.key, () => {}) // result ignored
return false
}
Expand Down Expand Up @@ -673,8 +670,7 @@ export class CookieJar {
callback: Callback<string | undefined>,
): void
getCookieString(url: string, callback: Callback<string | undefined>): void
getCookieString(url: string): Promise<string>
getCookieString(url: string, options: GetCookiesOptions): Promise<string>
getCookieString(url: string, options?: GetCookiesOptions): Promise<string>
getCookieString(
url: string,
options: GetCookiesOptions | Callback<string | undefined>,
Expand Down Expand Up @@ -729,10 +725,9 @@ export class CookieJar {
options: GetCookiesOptions,
callback: Callback<string[] | undefined>,
): void
getSetCookieStrings(url: string): Promise<string[] | undefined>
getSetCookieStrings(
url: string,
options: GetCookiesOptions,
options?: GetCookiesOptions,
): Promise<string[] | undefined>
getSetCookieStrings(
url: string,
Expand Down Expand Up @@ -921,8 +916,7 @@ export class CookieJar {

clone(callback: Callback<CookieJar>): void
clone(newStore: Store, callback: Callback<CookieJar>): void
clone(): Promise<CookieJar>
clone(newStore: Store): Promise<CookieJar>
clone(newStore?: Store): Promise<CookieJar>
clone(
newStore?: Store | Callback<CookieJar>,
callback?: Callback<CookieJar>,
Expand Down Expand Up @@ -1041,10 +1035,9 @@ export class CookieJar {
store: Store,
callback: Callback<CookieJar>,
): void
static deserialize(strOrObj: string | object): Promise<CookieJar>
static deserialize(
strOrObj: string | object,
store: Store,
store?: Store,
): Promise<CookieJar>
static deserialize(
strOrObj: string | object,
Expand Down Expand Up @@ -1074,7 +1067,7 @@ export class CookieJar {
serialized = strOrObj
}

const readSerializedProperty = (property: string): unknown | undefined => {
const readSerializedProperty = (property: string): unknown => {
return serialized &&
typeof serialized === 'object' &&
inOperator(property, serialized)
Expand Down Expand Up @@ -1119,7 +1112,7 @@ export class CookieJar {
const serialized: unknown =
typeof strOrObj === 'string' ? JSON.parse(strOrObj) : strOrObj

const readSerializedProperty = (property: string): unknown | undefined => {
const readSerializedProperty = (property: string): unknown => {
return serialized &&
typeof serialized === 'object' &&
inOperator(property, serialized)
Expand Down
18 changes: 3 additions & 15 deletions lib/memstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ export class MemoryCookieStore extends Store {
callback?: Callback<void>,
): unknown {
// this seems wrong but it stops typescript from complaining and all the test pass...
// eslint-disable-next-line @typescript-eslint/no-empty-function
callback = callback ?? function () {}

// updateCookie() may avoid updating cookies that are identical. For example,
Expand Down Expand Up @@ -244,18 +243,7 @@ export class MemoryCookieStore extends Store {
): unknown {
const promiseCallback = createPromiseCallback<void>(callback)
const cb = promiseCallback.callback

const domainEntry = this.idx[domain]
if (domainEntry) {
const pathEntry = domainEntry[path]
if (pathEntry) {
const keyEntry = pathEntry[key]
if (keyEntry) {
delete pathEntry[key]
}
}
}

delete this.idx[domain]?.[path]?.[key]
cb(null, undefined)
return promiseCallback.promise
}
Expand All @@ -277,9 +265,9 @@ export class MemoryCookieStore extends Store {
const domainEntry = this.idx[domain]
if (domainEntry) {
if (path) {
delete domainEntry[path]
delete domainEntry?.[path]
} else {
delete this.idx[domain]
delete this.idx?.[domain]
}
}

Expand Down
Loading

0 comments on commit c95413c

Please sign in to comment.