FIX: avoid eager rewrite of /my* routes (#23011)

This commit is contained in:
Renato Atilio 2023-08-08 09:43:41 -03:00 committed by GitHub
parent b7953b2562
commit 904ab8deaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -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");

View File

@ -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"),