Skip to content

A platform for community discussion. Free, open, simple.

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

Vinoth Kannanaa017f276f19
diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js
index 682a6259363..b5b582fa5ca 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 b5f755a1433..a10a244fb22 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"
+ );
+});