From 3eca4a53d0845bb29d6743450174fa0eb8d89ed0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 30 Jul 2024 15:10:49 +0530 Subject: [PATCH] Redirect to home on invalid book id --- src/calibre/srv/legacy.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/srv/legacy.py b/src/calibre/srv/legacy.py index 6c5aa803c9..72c6153e4d 100644 --- a/src/calibre/srv/legacy.py +++ b/src/calibre/srv/legacy.py @@ -254,9 +254,13 @@ def mobile(ctx, rd): @endpoint('/browse/{+rest=""}') def browse(ctx, rd, rest): if rest.startswith('book/'): + try: + book_id = int(rest[5:]) + except Exception: + raise HTTPRedirect(ctx.url_for(None)) # implementation of https://bugs.launchpad.net/calibre/+bug/1698411 # redirect old server book URLs to new URLs - redirect = ctx.url_for(None) + '#book_id=' + int(rest[5:]) + "&panel=book_details" + redirect = ctx.url_for(None) + f'#book_id={book_id}&panel=book_details' from lxml import etree as ET return html(ctx, rd, endpoint, E.html(E.head(