E.g. https://builds.sr.ht/~sircmpwn/ responds with 404; this is due to
how flask deals with trailing slashes in route's definition:
https://flask.palletsprojects.com/en/2.3.x/api/#url-route-registrations
Since there are sub-routes like /~<username>/job/<id>, the user might be tempted
to navigate up by editing the URL and getting a 404 when they "forget"
to remove the trailing / is annoying.
Now with the rule ending with a /, both requesting with and without the
trailing slash would work.
---
buildsrht/blueprints/jobs.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/buildsrht/blueprints/jobs.py b/buildsrht/blueprints/jobs.py
index d37c1a5..64d823d 100644
--- a/buildsrht/blueprints/jobs.py
@@ -283,7 +283,7 @@ def cancel(job_id):
requests_session.post(f"http://{job.runner}/job/{job.id}/cancel")
return redirect("/~" + current_user.username + "/job/" + str(job.id))
-@jobs.route("/~<username>")+@jobs.route("/~<username>/")def user(username):
user = User.query.filter(User.username == username).first()
if not user:
--
2.39.2
The trailing slash issue has come up a few times, and this kind of
patchwork one-route-at-a-time solution has been rejected before. The
appropriate fix for this is to come up with a plan for dealing with
trailing slashes site-wide and apply a solution consitently to all
routes in all services at once.
On Tuesday, June 27th, 2023 at 10:06, Drew DeVault <sir@cmpwn.com> wrote:
> The trailing slash issue has come up a few times, and this kind of> patchwork one-route-at-a-time solution has been rejected before. The> appropriate fix for this is to come up with a plan for dealing with> trailing slashes site-wide and apply a solution consitently to all> routes in all services at once.
See e.g. https://git.sr.ht/~sircmpwn/git.sr.ht/commit/2a5f5783d60bdb476352f3087bd77ea271338822