Skip to content

Commit f4e93a0

Browse files
committed
Prevent infinite redirect for doc-router /doc[^/]
Previously, it would just put the slice in the Location with no regards for what was in there. If there was no slash after the `/doc`, it would issue a relative redirect, which was still under `/doc`, causing an infinite redirect. - /docs/std -> s/std - /docs/s/std -> s/s/std - /docs/s/s/s/std -> ... We prevent this behavior here by only applying the `/doc` redirect if there is a slash directly after it, causing the default /stable rewrite fallback to be applied to everything else, which will in practice lead to nice 404 page. This should not break anything as all such queries currently run into these loops, including plain `/doc`.
1 parent a525d15 commit f4e93a0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

terragrunt/modules/release-distribution/lambdas/doc-router/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ exports.handler = (event, context, callback) => {
104104
}
105105

106106
// Docs used to be under /doc, so redirect those for now
107-
if (request.uri.startsWith('/doc')) {
107+
if (request.uri.startsWith('/doc/')) {
108108
return redirect(request.uri.slice(4), callback);
109109
}
110110

terragrunt/modules/release-distribution/lambdas/doc-router/test.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// A test that asserts that the redirects work correctly.
2+
// It can be run with
3+
// node --test test.mjs
4+
15
import { test } from "node:test";
26
import assert from "node:assert";
37
import lambda from "./index.js";
@@ -68,3 +72,8 @@ test("ensure the default rewrite to /stable", async (t) => {
6872
const request = await invokeHandler("/std");
6973
assert.strictEqual(request.uri, "/stable/std");
7074
});
75+
76+
test("ensure no infinite redirect for /doc[^/]", async (t) => {
77+
const request = await invokeHandler("/docs/std");
78+
assert.strictEqual(request.uri, "/stable/docs/std");
79+
});

0 commit comments

Comments
 (0)