Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
docs: Remove trailing slash from canonical URL for non-root docs.
Lauryn Menard9de461820261
diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.pyindex bb9c7d25c24..c79146956e2 100644--- a/zerver/tests/test_docs.py+++ b/zerver/tests/test_docs.py@@ -251,6 +251,14 @@ class DocPageTest(ZulipTestCase):)self.assertEqual(result.status_code, 404)+ result = self.client_get(+ # Non-root API docs pages do not have a trailing slash.+ "/api/changelog/",+ follow=True,+ HTTP_X_REQUESTED_WITH="XMLHttpRequest",+ )+ self.assertEqual(result.status_code, 404)+def test_dev_environment_endpoints(self) -> None:self._test("/devlogin/", ["Normal users"])self._test("/devtools/", ["Useful development URLs"])diff --git a/zerver/views/documentation.py b/zerver/views/documentation.pyindex 626ef32d327..4f075738a86 100644--- a/zerver/views/documentation.py+++ b/zerver/views/documentation.py@@ -77,7 +77,12 @@ def add_api_url_context(def add_canonical_link_context(context: dict[str, Any], request: HttpRequest) -> None:- context["REL_CANONICAL_LINK"] = f"https://zulip.com{request.path}"+ if request.path in ["/api/", "/policies/", "/integrations/"]:+ # Root doc pages have a trailing slash in the canonical URL.+ canonical_path = request.path+ else:+ canonical_path = request.path.removesuffix("/")+ context["REL_CANONICAL_LINK"] = f"https://zulip.com{canonical_path}"class ApiURLView(TemplateView):