Skip to content

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

FIX: Strip subfolder prefix before SERVER_SIDE_ONLY check in routeTo (#37996)

Régis Hanol1a22ddb55e3a
diff --git a/frontend/discourse/app/lib/url.js b/frontend/discourse/app/lib/url.js
index d6d2090b3e5..eab4a85e4d5 100644
--- a/frontend/discourse/app/lib/url.js
+++ b/frontend/discourse/app/lib/url.js
@@ -238,7 +238,10 @@ class DiscourseURL extends EmberObject {
return this.redirectTo(path);
}
- const serverSide = SERVER_SIDE_ONLY.some((r) => pathname.match(r));
+ const pathnameWithoutPrefix = withoutPrefix(pathname);
+ const serverSide = SERVER_SIDE_ONLY.some((r) =>
+ pathnameWithoutPrefix.match(r)
+ );
if (serverSide) {
this.redirectTo(path);
return;
diff --git a/frontend/discourse/tests/unit/lib/url-test.js b/frontend/discourse/tests/unit/lib/url-test.js
index 27956c04473..805a90a766e 100644
--- a/frontend/discourse/tests/unit/lib/url-test.js
+++ b/frontend/discourse/tests/unit/lib/url-test.js
@@ -264,6 +264,30 @@ module("Unit | Utility | url", function (hooks) {
);
});
+ test("routeTo redirects server-side-only URLs on subfolder setup", async function (assert) {
+ setPrefix("/forum");
+ sinon.stub(DiscourseURL, "redirectTo");
+ sinon.stub(DiscourseURL, "handleURL");
+
+ DiscourseURL.routeTo("/forum/uploads/short-url/test.csv.gz");
+ assert.true(
+ DiscourseURL.redirectTo.calledWith(
+ "/forum/uploads/short-url/test.csv.gz"
+ ),
+ "uploads short-url on subfolder is redirected to server"
+ );
+
+ DiscourseURL.redirectTo.resetHistory();
+
+ DiscourseURL.routeTo("/forum/secure-uploads/original/1X/test.pdf");
+ assert.true(
+ DiscourseURL.redirectTo.calledWith(
+ "/forum/secure-uploads/original/1X/test.pdf"
+ ),
+ "secure-uploads on subfolder is redirected to server"
+ );
+ });
+
test("anchor handling", async function (assert) {
sinon.stub(DiscourseURL, "jumpToElement");
sinon.stub(DiscourseURL, "replaceState");