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
Use dash encoding for table names and row primary keys in URLs #1648
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1648 +/- ##
==========================================
+ Coverage 92.03% 92.05% +0.02%
==========================================
Files 34 34
Lines 4557 4570 +13
==========================================
+ Hits 4194 4207 +13
Misses 363 363
Continue to review full report at Codecov.
|
Change of plan: based on extensive conversations on Twitter - see #1439 (comment) - I'm going to try a variant of this which is basically percent-encoding but with a hyphen instead of a percent symbol. Reason being that the current scheme doesn't handle the case of |
For consistency, I'm going to change how datasette/datasette/views/table.py Lines 501 to 507 in de810f4
datasette/datasette/utils/__init__.py Lines 114 to 116 in de810f4
I'm going to change those to use dash-encoding instead. I considered looking for |
Just spotted this: datasette/datasette/views/base.py Lines 203 to 216 in de810f4
Maybe the db name should use dash encoding too? If so, relevant code includes this bit: datasette/datasette/url_builder.py Lines 30 to 38 in de810f4
|
Yes, I'm going to do this. At the moment if a DB file is called |
I may have to do extra work here def database(self, database, format=None):
db = self.ds.databases[database]
if self.ds.setting("hash_urls") and db.hash:
path = self.path(
f"{dash_encode(database)}-{db.hash[:HASH_LENGTH]}", format=format
)
else:
path = self.path(dash_encode(database), format=format)
return path The URLs that incorporate a hash have a Might be able to solve that like so: async def resolve_db_name(self, request, db_name, **kwargs):
hash = None
name = None
decoded_name = dash_decode(db_name)
if decoded_name not in self.ds.databases and "-" in db_name:
# No matching DB found, maybe it's a name-hash?
name_bit, hash_bit = db_name.rsplit("-", 1)
if dash_decode(name_bit) not in self.ds.databases:
raise NotFound(f"Database not found: {name}")
else:
name = dash_decode(name_bit)
hash = hash_bit
else:
name = decoded_name |
Refs #1439.
dash_encode
/dash_decode
functions?_next=
pagination tokensImplement redirects from previous- separate issue: Implement redirects from old % encoding to new dash encoding #1650%
URLs that replace those with-