From 6055a7bcebe92b1d236d8c50f7293cbbb2232e2f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 2 Apr 2018 10:29:32 -0700 Subject: [PATCH] bugdown: Clean up rewrite_if_relative_link. This implementation is more obviously correct, and may fix a corner case where a `/` is missing after the realm URI. --- zerver/lib/bugdown/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.py index e0136437cd..fe3a43dc98 100644 --- a/zerver/lib/bugdown/__init__.py +++ b/zerver/lib/bugdown/__init__.py @@ -86,9 +86,10 @@ def rewrite_if_relative_link(link: str) -> str: instead of opening a new tab. """ if db_data: - if link.startswith(db_data['realm_uri']): + realm_uri_prefix = db_data['realm_uri'] + "/" + if link.startswith(realm_uri_prefix): # +1 to skip the `/` before the hash link. - return link[len(db_data['realm_uri']) + 1:] + return link[len(realm_uri_prefix):] return link