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

make decoder run only on the respective cookie (and not all cookies) #3

Closed
schlichtanders opened this issue Dec 3, 2024 · 4 comments
Labels

Comments

@schlichtanders
Copy link

Using this code for 15 minutes I realized that the cookies parsing functionality and all its respective utility as decode and encode tools will always be run for all cookies.

It would make much more sense to the user if the decode function would only be run for the very cookie which is identified by name.

@schlichtanders schlichtanders changed the title add decoder and encoder features which run only on the respective cookie (and not all cookies) make decoder run only on the respective cookie (and not all cookies) Dec 3, 2024
@dqunbp dqunbp closed this as completed in 853650f Dec 8, 2024
github-actions bot pushed a commit that referenced this issue Dec 8, 2024
# [3.0.0](v2.1.1...v3.0.0) (2024-12-08)

### Features

* update decode option handling to accept a decoding function directly ([853650f](853650f)), closes [#3](#3)

### BREAKING CHANGES

* the cookie package version bumbed up from 0.7.2 to 1.0.2
Copy link

github-actions bot commented Dec 8, 2024

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dqunbp
Copy link
Owner

dqunbp commented Dec 8, 2024

@schlichtanders The downside of this approach is that you won't be able to apply the decode function to a raw value from a cookies; By default, cookie lib will apply decodeUriComponent will for each value, and then decode will be applied to the target value.

@dqunbp
Copy link
Owner

dqunbp commented Dec 8, 2024

@schlichtanders In release 3.0.0, this works as you requested, but starting from 3.1.0, I reverted it to the previous behavior. The fact that it runs for the all values from the cookies is a small price to pay for the ability to fully control encoding and decoding. Otherwise, it would be impossible to prevent decodeURIComponent from being called before custom decode function. Alternatively, I would have to implement the parsing yourself without using cookie lib, which goes against the original intent of this hook—to leverage the cookies library under the hood, as it is already a proven and popular solution.

@schlichtanders
Copy link
Author

thank you for your effort and all your thoughts. makes sense

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

No branches or pull requests

2 participants