mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:02:46 +08:00
FIX: Do not strip //
from the middle of URLs in discourse-url (#28210)
Protocol/domain should only be stripped when they occur at the beginning of a URL
This commit is contained in:
parent
624dc87321
commit
f70a65ea02
|
@ -214,7 +214,7 @@ class DiscourseURL extends EmberObject {
|
|||
return this.redirectTo(path);
|
||||
}
|
||||
|
||||
const pathname = path.replace(/(https?\:)?\/\/[^\/]+/, "");
|
||||
const pathname = path.replace(/^(https?\:)?\/\/[^\/]+/, "");
|
||||
|
||||
if (!this.isInternal(path)) {
|
||||
return this.redirectTo(path);
|
||||
|
|
|
@ -114,6 +114,40 @@ module("Unit | Utility | url", function (hooks) {
|
|||
);
|
||||
});
|
||||
|
||||
test("routeTo protocol/domain stripping", async function (assert) {
|
||||
sinon.stub(DiscourseURL, "origin").get(() => "http://example.com");
|
||||
sinon.stub(DiscourseURL, "handleURL");
|
||||
sinon.stub(DiscourseURL, "router").get(() => {
|
||||
return {
|
||||
currentURL: "/bar",
|
||||
};
|
||||
});
|
||||
|
||||
DiscourseURL.routeTo("http://example.com/foo1");
|
||||
assert.ok(
|
||||
DiscourseURL.handleURL.calledWith(`/foo1`),
|
||||
"it strips the protocol and domain when http"
|
||||
);
|
||||
|
||||
DiscourseURL.routeTo("https://example.com/foo2");
|
||||
assert.ok(
|
||||
DiscourseURL.handleURL.calledWith(`/foo2`),
|
||||
"it strips the protocol and domain when https"
|
||||
);
|
||||
|
||||
DiscourseURL.routeTo("//example.com/foo3");
|
||||
assert.ok(
|
||||
DiscourseURL.handleURL.calledWith(`/foo3`),
|
||||
"it strips the protocol and domain when protocol-less"
|
||||
);
|
||||
|
||||
DiscourseURL.routeTo("https://example.com//foo4");
|
||||
assert.ok(
|
||||
DiscourseURL.handleURL.calledWith(`//foo4`),
|
||||
"it does not strip double-slash in the middle of urls"
|
||||
);
|
||||
});
|
||||
|
||||
test("routeTo does not rewrite routes started with /my", async function (assert) {
|
||||
logIn();
|
||||
sinon.stub(DiscourseURL, "router").get(() => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user