tough-cookie: v2.5.0 : str.trim() is not a function
We’re using tough-cookie ^2.4.3 (which actually installs 2.5.0) with request ^2.88.0.
This code worked with 2.4.3 :
const cookiesJar = requestModule.jar();
_.forEach(initialCookies, (cookie: Object) => {
const newCookie = toughCookie.fromJSON(JSON.stringify(cookie));
const hostUrl = `${initialOptions.protocol}//${initialOptions.host}/`;
cookiesJar.setCookie(newCookie, hostUrl);
});
But we’re getting the following error with 2.5.0 :
TypeError: str.trim is not a function
at Function.parse (node_modules/request/node_modules/tough-cookie/lib/cookie.js:429:13)
at CookieJar.setCookie (node_modules/request/node_modules/tough-cookie/lib/cookie.js:1011:21)
at CookieJar.setCookieSync (node_modules/request/node_modules/tough-cookie/lib/cookie.js:1402:18)
at RequestJar.setCookie (node_modules/request/lib/cookies.js:25:20)
Any hint about what could cause this issue in 2.5.0?
Thanks!
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 15
- Comments: 24 (10 by maintainers)
Commits related to this issue
- setCookie arg must be Cookie or string Addresses #132, partially. The error message is clearer, indicating that this method only accepts the afformentioned types. The part of 132 that it doesn't addr... — committed to salesforce/tough-cookie by stash 5 years ago
- Added missing progress-ring stub (#132) — committed to salesforce/tough-cookie by pozil 4 years ago
typescript
(cookie instanceof Cookie)return false.@awaterma
workaround
I’m still seeing this with v3.0.1.
Thanks @gombosg.
instanceofdefinitely goes on an actual Function object, so if you have two functions namedCookie(the constructor), theinstanceofand==and===operators will all return false.FWIW, I’m able to reproduce this in a test now with request 2.88.0 and node 11.4.0. I’ll look into it again later today.