Skip to content

Commit 0918388

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 0918388

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ test("ensure the default rewrite to /stable", async (t) => {
6868
const request = await invokeHandler("/std");
6969
assert.strictEqual(request.uri, "/stable/std");
7070
});
71+
72+
test("ensure no infinite redirect for /doc[^/]", async (t) => {
73+
const request = await invokeHandler("/docs/std");
74+
assert.strictEqual(request.uri, "/stable/docs/std");
75+
});

0 commit comments

Comments
 (0)