-
-
Notifications
You must be signed in to change notification settings - Fork 169
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
Importing a netscape format cookie file fails if a cookie is not assigned a value #173
Comments
Cookie-Editor: v1.13.0 Tested on:
Both are affected by this issue. To reproduce the issue:
Thanks for looking into this. |
Error is thrown because an empty value is not supported, we expect all 7 fields to be present: cookie-editor/interface/lib/netscapeFormat.js Lines 30 to 33 in 0d88685
But there is no official spec that I can find online. If desired, an empty value can easily be supported. Side-note: A spec is mentioned in the code cookie-editor/interface/lib/netscapeFormat.js Lines 54 to 56 in 0d88685
But it doesn't seem to be followed (e.g: the date format isn't of type |
For the Netscape format, I mostly based myself on the info available on curl's website: https://curl.se/docs/http-cookies.html and from info found in the discussion of #17.
I didn't get a chance to try it out, but in theory an empty value should work if there is still the right amount of tabs, split should just leave it empty.
There's so many places mentioning using a timestamp instead of a date format, it's honestly confusing. The specs officially says it's supposed to be a long date format, but for now I'll keep the timestamp since it works and that's what curl also mentions.
It seems to be pretty standard to include this header when saving cookies to a netscape format, so I also included it. It's not strictly needed. |
It does export the cookies in the correct format with a trailing tab at the end of the line for blank cookies, not sure why does it have a problem importing them. You are right in that it should work - split() returns the correct number of tokens in this case. Perhaps the problem lies elsewhere?
Maybe that's a very old version of the "spec", as Netscape itself is quite ancient. There was a version that even preceded this with just 6 fields as described here: https://www.ibm.com/support/pages/how-identify-version-0-netscape-cookies
I believe the first line was required as part of the spec and some software/libraries still require it, but the next two lines are just comments that curl added to its version of the cookies file. In fact, the current version of curl uses a different URL now - the one you referenced above (https://curl.se/docs/http-cookies.html), which in turn links to this old spec. Wget adds a similar header too, but it doesn't reference any doc or spec. I think it would be better to refer to https://curl.se/docs/http-cookies.html here instead, as it has more context and provides the details of the file format that's actually being used. |
Okay, I figured where the problem is. It's the trim() being called for each line read, before the split() is called - that gets rid of the trailing '\t' leading to this error. Removing 'line = line.trim(); ' on line 17 and changing the subsequent check on line 18 to 'if (!line.trim().length)' should take care of this issue. cookie-editor/interface/lib/netscapeFormat.js Lines 16 to 33 in 0d88685
|
Another alternative would be to replace That way we'd still allow for some flexibility when writing out the cookies, since we rely on the HttpPrefix and the comments starting at index 0. Good on you for finding the issue 🎉 |
Fails with Error: "The input is not in a valid format"
It doesn't have a problem with blank cookies otherwise.
It's even able to export these cookies to netscape format, but can't import what it just exported if one of the cookies is blank.
If exporting to JSON format, export & import functions work as expected.
The text was updated successfully, but these errors were encountered: