-
Notifications
You must be signed in to change notification settings - Fork 209
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
Enable parsing cookies with an empty or no key #49
Conversation
Hi @Sebmaster. Thanks for the pull request! If you're interested, it needs a bit of work. Please note that SFDC requires a CLA to be signed in order to accept any PR (either by you or your employer). We got rid of a similar I'd like to try to maintain RFC compliance if possible, so unless this is how the RFC says to parse it (I honestly haven't looked yet), I don't think this feature should be "on" by default. You've implemented it as "off" by default, which is great, but I wanted to be clear that we can't just switch to Thanks again for taking the time to contribute this PR 💯 |
I actually thought of another method in the meanwhile: Make the parameter an options object instead and check for explicit existence of a strict property in that object. If the given param is either not an object, or that key doesn't exist, we just ignore it.
So, according to the RFC this is not actually a valid cookie - I think. However, all browsers can properly parse this cookie. Sending a
Where can I find this CLA? |
@stash-sfdc @Sebmaster the thing is that nobody fully implements RFC spec 🎉 As far as I remember even IETF tests violate it at some cases in favor of common browser behavior. So, if it doesn't break existing tests and if this behavior is consistent across browsers, I'd rather keep it as non-optional. |
@inikulin OK, agreed: if it's both IETF-test-compliant and consistent, then it should be the default behavior. |
So we remove the strict param altogether? As far as I remember this starts breaking the (IETF part of the) test suite, so what should I do about that? |
@Sebmaster please see https://github.com/forcedotcom/idecore/wiki/Contributing-Code regarding the CLA. |
@Sebmaster OK, i follow the key-versus-value logic. Thanks for explaining that clearly! If on-by-default breaks the suite, then perhaps an options Object as the second parameter (that handles the Array#map use-case) would be best. |
@Sebmaster I have a feeling what we can make work both, we just need a more sophisticated regexp. No facts, just an assumption 🚶 |
If I remember correctly the IETF suite explicitly tests to disallow the format we want to allow here, so I doubt it. Will look into it though. Yeah, see for example: https://github.com/SalesforceEng/tough-cookie/blob/master/test/ietf_data/parser.json#L1515, which fails. |
Moved to options object and also added another test I found in the IETF tests which looked like a pretty interesting scenario to support (verified in browsers). Will get the CLA done tomorrow. |
CLA is done too now. |
Confirm CLA accepted! Welcome @Sebmaster! |
@@ -885,7 +899,7 @@ CookieJar.prototype.setCookie = function(cookie, url, options, cb) { | |||
|
|||
// S5.3 step 1 | |||
if (!(cookie instanceof Cookie)) { | |||
cookie = Cookie.parse(cookie); | |||
cookie = Cookie.parse(cookie, !options || !options.loose); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this pass {loose: options.loose}
or maybe just options
entirely? On a hunch this might require code coverage -- try adding jar.setCookieSync('=a', url)
and jar.setCookieSync('=a',url,{loose:true})
and make sure those behave as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, fixed and added tests for it.
@Sebmaster looks good to me. Ready to be merged? |
Yep, should be good. 🎉 |
Enable parsing cookies with an empty or no key
* update README with deasync workaround * update wording slightly * grammer tweak
This is basically a proposal for fixing #10 since I came across an instance where I'd need this.
I'm not sure about the handling of the "re-introduced" strict parameter. In order to not change behaviour when not given I set it to default to true for now, but I guess we'd need a better solution here?