FIX: replace `fullPath` while rewriting the `/my/` URLs.

FIX: replace fullPath while rewriting the /my/ URLs.

And added the tests. Follow-up to cdca5a2ee44d39a89ebfca5cfbebb765cecdc882

diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js
index 682a625..b5b582f 100644
--- a/app/assets/javascripts/discourse/app/lib/url.js
+++ b/app/assets/javascripts/discourse/app/lib/url.js
@@ -247,7 +247,7 @@ const DiscourseURL = EmberObject.extend({
     if (fullPath.indexOf(myPath) === 0) {
       const currentUser = User.current();
       if (currentUser) {
-        path = path.replace(
+        path = fullPath.replace(
           myPath,
           userPath(currentUser.get("username_lower"))
         );
diff --git a/test/javascripts/lib/url-test.js b/test/javascripts/lib/url-test.js
index b5f755a..a10a244 100644
--- a/test/javascripts/lib/url-test.js
+++ b/test/javascripts/lib/url-test.js
@@ -1,5 +1,7 @@
 import DiscourseURL, { userPath } from "discourse/lib/url";
 import { setPrefix } from "discourse-common/lib/get-url";
+import { logIn } from "helpers/qunit-helpers";
+import User from "discourse/models/user";
 
 QUnit.module("lib:url");
 
@@ -66,3 +68,16 @@ QUnit.test("userPath with prefix", assert => {
   assert.equal(userPath("eviltrout"), "/forum/u/eviltrout");
   assert.equal(userPath("hp.json"), "/forum/u/hp.json");
 });
+
+QUnit.test("routeTo with prefix", async assert => {
+  setPrefix("/forum");
+  logIn();
+  const user = User.current();
+
+  sandbox.stub(DiscourseURL, "handleURL");
+  DiscourseURL.routeTo("/my/messages");
+  assert.ok(
+    DiscourseURL.handleURL.calledWith(`/u/${user.username}/messages`),
+    "it should navigate to the messages page"
+  );
+});

GitHub sha: aa017f27

1 Like