-
Notifications
You must be signed in to change notification settings - Fork 57
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
[FIX] Prevent keys from starting with slashes #172
Conversation
Thank you @Firepup6500! Could you add a test in https://github.com/replit/replit-py/blob/master/tests/test_database.py? |
Code seems to be working as running from replit import db
db["/abc"] = "d"
print(db["/abc"]) I'm not sure what's causing the Edit: Not using |
Alright, finally figured it out. @airportyh Could you review this again? |
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.
Beautiful! Thank you.
3298cfa
to
43c9c21
Compare
If a key starts with a slash, then it becomes undeletable and prevents database purges from working properly as well. This prevents that from occuring by stripping slashes from the left of the key name.
21a68a8
to
6a12305
Compare
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.
Thanks!
Wouldn't it be better to figure out why adding a leading forward slash causes problems instead of removing them? Sounds like an issue with escaping the keys or something. |
@lafkpages The way I read this initially suggested that it was impossible for keys to have started with a slash, so this would effectively be a no-op. Upon rereading the initial report, it may indeed have been an error to make this change without similar changes in the other libraries, as well as the requisite changes on the backend to establish consistency. I'll raise your point with the team next week, we'll find a way forward; for the time being, if this has impacted your program, please stay on Thank you! |
@lafkpages It took a bit longer to get back to this than anticipated, but I'm happy to say #218 is up for review. Thanks again for pointing this out! |
* poetry lock * Formatting * Avoid object has no attribute '_refresh_timer' When called without a refresh function we end up getting AttributeError: 'AsyncDatabase' object has no attribute '_refresh_timer' on attempted close. Fix this. * Revert #172 This was a good first attempt, but still prevented users from deleting the keys they'd created * Switch delete method to use new multipart/form-data delete method that supports deleting keys with leading slashes * Adjusting tests to reflect the gap in getting slashy keys
If a key starts with a slash, then it becomes undeletable and prevents database purges from working properly as well. This prevents that from occuring by stripping slashes from the left of the key name.
Why
At least two separate occurrences where users have accidentally set a key that starts with a slash, and therefore can no longer remove the key or cleared their database.
What changed
Changed all references to
key
ork
when setting a key-value pair tokeyStrip(key)
andkeyStrip(k)
respectively.Test plan
Attempted to set keys starting with slashes, then subsequently remove them and/or purge the database.
Rollout
Prevents keys from being set with a slash in the future, which was is less breaking than the existing behavior (which is to not process the keys at all)