mirror of
https://github.com/discourse/discourse.git
synced 2025-04-28 00:14:34 +08:00
FIX: avoid eager rewrite of /my* routes (#23011)
This commit is contained in:
parent
b7953b2562
commit
904ab8deaa
@ -227,14 +227,14 @@ const DiscourseURL = EmberObject.extend({
|
|||||||
path = path.replace(/(https?\:)?\/\/[^\/]+/, "");
|
path = path.replace(/(https?\:)?\/\/[^\/]+/, "");
|
||||||
|
|
||||||
// Rewrite /my/* urls
|
// Rewrite /my/* urls
|
||||||
let myPath = getURL("/my");
|
let myPath = getURL("/my/");
|
||||||
const fullPath = getURL(path);
|
const fullPath = getURL(path);
|
||||||
if (fullPath.startsWith(myPath)) {
|
if (fullPath.startsWith(myPath)) {
|
||||||
const currentUser = User.current();
|
const currentUser = User.current();
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
path = fullPath.replace(
|
path = fullPath.replace(
|
||||||
myPath,
|
myPath,
|
||||||
userPath(currentUser.get("username_lower"))
|
`${userPath(currentUser.get("username_lower"))}/`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return this.redirectTo("/login-preferences");
|
return this.redirectTo("/login-preferences");
|
||||||
|
@ -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) {
|
test("prefixProtocol", async function (assert) {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
prefixProtocol("mailto:mr-beaver@aol.com"),
|
prefixProtocol("mailto:mr-beaver@aol.com"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user