From 2b9c13f2cf2b2bf9973e30f06bfa883a90caa8eb Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Mon, 16 Oct 2023 14:15:59 +0530 Subject: [PATCH] Guarantee that badge_base_url will always have a trailing / Before this, the callable could return something without a trailing slash, and that could break things. --- binderhub/base.py | 3 +++ binderhub/static/js/src/constants.js | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/binderhub/base.py b/binderhub/base.py index 33474fcce..b002bbd95 100644 --- a/binderhub/base.py +++ b/binderhub/base.py @@ -172,6 +172,9 @@ def get_badge_base_url(self): badge_base_url = self.settings["badge_base_url"] if callable(badge_base_url): badge_base_url = badge_base_url(self) + # Make sure the url has a trailing slash + if not badge_base_url.endswith("/"): + badge_base_url += "/" return badge_base_url def render_template(self, name, **extra_ns): diff --git a/binderhub/static/js/src/constants.js b/binderhub/static/js/src/constants.js index 4098f17bf..6de63a75a 100644 --- a/binderhub/static/js/src/constants.js +++ b/binderhub/static/js/src/constants.js @@ -15,7 +15,9 @@ const badge_base_url = document.getElementById("badge-base-url").dataset.url; * Base URL to use for both badge images as well as launch links. * * If not explicitly set, will default to BASE_URL. Primarily set up different than BASE_URL - * when used as part of a federation + * when used as part of a federation. + * + * Guaranteed to have a trailing slash by the binderhub python configuration. */ export const BADGE_BASE_URL = badge_base_url ? new URL(badge_base_url, document.location.origin)