Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validation errors not calling callbacks #424

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

colincasey
Copy link
Contributor

I noticed this issue while upgrading tough-cookie in jsdom which was causing their test suite to hang. There is a sneaky little bug around our internal validations where, in several methods that accept callbacks, our validations error out directly and never invoke the given callback with the error. This can lead to code that waits for a callback that will never complete. This also affects functions wrapped in Sync which leverage callbacks to capture their return values.

The affected methods were:

  • getCookiesSync
  • getCookieString
  • getSetCookieStrings
  • serializeSync
  • serialize
  • setCookieSync
  • setCookie
  • getCookiesSync
  • getCookies

There were also several validation errors hiding in support methods. These appear to be redundant since the type signatures present already do much of the validation. These have been removed from:

  • checkSameSiteContext
  • isHostPrefixConditionMet
  • isSecurePrefixConditionMet
  • cookieCompare
  • formatDate
  • permutePath

…was causing their test suite to hang. There is a sneaky little bug around our internal validations where, in several methods that accept callbacks, our validations error out directly and never invoke the given callback with the error. This can lead to code that waits for a callback that will never complete. This also affects functions wrapped in `Sync` which leverage callbacks to capture their return values.

The affected methods were:
- `getCookiesSync`
- `getCookieString`
- `getSetCookieStrings`
- `serializeSync`
- `serialize`
- `setCookieSync`
- `setCookie`
- `getCookiesSync`
- `getCookies`

There were also several validation errors hiding in support methods. These appear to be redundant since the type signatures present already do much of the validation. These have been removed from:
- `checkSameSiteContext`
- `isHostPrefixConditionMet`
- `isSecurePrefixConditionMet`
- `cookieCompare`
- `formatDate`
- `permutePath`
@colincasey colincasey self-assigned this Jun 23, 2024
throw err
}
}

// These seem to be false positives; it can't detect that the value may be changed in the callback
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// These seem to be false positives; it can't detect that the value may be changed in the callback

Comment is for the removed // eslint-disable

Comment on lines +337 to +341
if (err instanceof Error) {
syncErr = err
} else {
throw err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere we just cast err as Error, why be particular here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants