From 904ab8deaa7aee95a6111c099055832be78049a8 Mon Sep 17 00:00:00 2001 From: Renato Atilio Date: Tue, 8 Aug 2023 09:43:41 -0300 Subject: [PATCH] FIX: avoid eager rewrite of /my* routes (#23011) --- app/assets/javascripts/discourse/app/lib/url.js | 4 ++-- .../discourse/tests/unit/lib/url-test.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js index 7864a0d1fac..4da3a49c455 100644 --- a/app/assets/javascripts/discourse/app/lib/url.js +++ b/app/assets/javascripts/discourse/app/lib/url.js @@ -227,14 +227,14 @@ const DiscourseURL = EmberObject.extend({ path = path.replace(/(https?\:)?\/\/[^\/]+/, ""); // Rewrite /my/* urls - let myPath = getURL("/my"); + let myPath = getURL("/my/"); const fullPath = getURL(path); if (fullPath.startsWith(myPath)) { const currentUser = User.current(); if (currentUser) { path = fullPath.replace( myPath, - userPath(currentUser.get("username_lower")) + `${userPath(currentUser.get("username_lower"))}/` ); } else { return this.redirectTo("/login-preferences"); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/url-test.js b/app/assets/javascripts/discourse/tests/unit/lib/url-test.js index e7ea1a3d202..4533b333285 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/url-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/url-test.js @@ -90,6 +90,19 @@ module("Unit | Utility | url", function () { ); }); + test("routeTo does not rewrite routes started with /my", async function (assert) { + logIn(); + sinon.stub(DiscourseURL, "router").get(() => { + return { currentURL: "/" }; + }); + sinon.stub(DiscourseURL, "handleURL"); + DiscourseURL.routeTo("/myfeed"); + assert.ok( + DiscourseURL.handleURL.calledWith(`/myfeed`), + "it should navigate to the unmodified route" + ); + }); + test("prefixProtocol", async function (assert) { assert.strictEqual( prefixProtocol("mailto:mr-beaver@aol.com"),