fix: edge case for redirects on / (#29180)

Because all slashes are stripped this endpoint becomes `""` which is not
a valid key for redis hash.
This commit is contained in:
Ankush Menat 2025-01-15 14:35:19 +05:30 committed by GitHub
parent 584727f5e7
commit d219353877
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -115,7 +115,7 @@ def resolve_redirect(path, query_string=None):
]
"""
redirect_to = frappe.cache.hget("website_redirects", path)
redirect_to = frappe.cache.hget("website_redirects", path or "/")
if redirect_to:
if isinstance(redirect_to, dict):
frappe.flags.redirect_location = redirect_to["path"]
@ -150,11 +150,11 @@ def resolve_redirect(path, query_string=None):
frappe.flags.redirect_location = redirect_to
status_code = rule.get("redirect_http_status") or 301
frappe.cache.hset(
"website_redirects", path_to_match, {"path": redirect_to, "status_code": status_code}
"website_redirects", path_to_match or "/", {"path": redirect_to, "status_code": status_code}
)
raise frappe.Redirect(status_code)
frappe.cache.hset("website_redirects", path_to_match, False)
frappe.cache.hset("website_redirects", path_to_match or "/", False)
def resolve_path(path):