-
Notifications
You must be signed in to change notification settings - Fork 611
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
URL Encode Key values #302
Conversation
Currently, the path is used for submitting data that may contain special characters. For example, if you try to set up bulk redirects in Workers with KV per https://developers.cloudflare.com/workers/recipes/bulk-redirects/, the key '/pathtoreplace' is stored in KV as 'pathtoreplace'. Currently, the caller has to URL encode the submission to the api.WriteWorkersKV() call to ensure the slashes get through. I can't think of a situation where we wouldn't want to URL encode a key as soon as the user submits it - adding an encode would the right thing instead of passively allowing data loss.
Let me know if I ought to go through the full process - I think the change is pretty self-evident and fixes a nasty bug for KV operations. |
That's what I get for working in the browser - missed the import.
As an aside, this bug caused me to add 40 KV pairs to a namespace missing the slashes - definitely not fun to troubleshoot. |
@ironsalsa Thank you for the Pull Request! A couple of things that we should address before shipping this one:
Once those are done, we can |
@jacobbednarz I've removed the extra cruft, but I'm not sure how to add a test on this one - is there a way to store a KV pair and retrieve it from a test to prove that a key with a "/" stores in the KV and can be retrieved from there? I'm rather new to writing Golang tests, so any suggestions would be appreciated. |
There are some existing tests in |
I'm running into problems - I can't get the original test with the original code to pass if you put a slash in the key, and I'm not 100% sure how to fix it since both the testing API and the code rely on that same key. I think this means the current test is catching the same bug I ran into, but no one tried with a slash before. @jacobbednarz you can replicate the error in the master branch by changing the line in workers_kv_test.go in func TestWorkersKV_WriteWorkersKV() from:
to:
Run the test and it will fail with a 404, since the client is calling a different URL and the API is publishing due to the URL encoding issue. Here's the error:
I'm going to be out of touch for over a week, so unless someone else jumps on this it may just sit around. |
@ironsalsa The issue there is that the value is being passed into |
@jacobbednarz @ironsalsa Turns out, even when you add the Given the hastle, I would just implement this without the test. It's a simple enough change. |
Seems reasonable given the extra context here 👍 I'm probably a little more cautious than most due to my day to day relying so heavily on git history and test cases but it seems like a suitable case where we don't need too heavy on test coverage. I'd opt for an alternative if/when this is involved in a regression though. |
Thanks for contribution, @Electroid ! |
* URL Encode Key values Currently, the path is used for submitting data that may contain special characters. For example, if you try to set up bulk redirects in Workers with KV per https://developers.cloudflare.com/workers/recipes/bulk-redirects/, the key '/pathtoreplace' is stored in KV as 'pathtoreplace'. Currently, the caller has to URL encode the submission to the api.WriteWorkersKV() call to ensure the slashes get through. I can't think of a situation where we wouldn't want to URL encode a key as soon as the user submits it - adding an encode would the right thing instead of passively allowing data loss. * Adding net/url import That's what I get for working in the browser - missed the import.
Currently, the path is used for submitting data that may contain special characters. For example, if you try to set up bulk redirects in Workers with KV per https://developers.cloudflare.com/workers/recipes/bulk-redirects/, the key '/pathtoreplace' is stored in KV as 'pathtoreplace'. Currently, the caller has to URL encode the submission to the api.WriteWorkersKV() call to ensure the slashes get through.
I can't think of a situation where we wouldn't want to URL encode a key as soon as the user submits it - adding an encode would do the right thing instead of passively allowing data loss.