Skip to content

Commit 80f7cfe

Browse files
maartenbaCopilot
andauthored
Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 078e2f1 commit 80f7cfe

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

astro/src/plugins/static-redirects.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,18 @@ async function detectDuplicateRedirects(
144144
? frontmatter.redirect_from
145145
: [frontmatter.redirect_from];
146146

147+
const normalizeRedirectSource = (source: string) => {
148+
const trimmed = source.trim();
149+
if (trimmed !== source) {
150+
logger.warn(
151+
`Trimmed whitespace from redirect_from entry in ${file}: ${JSON.stringify(source)} -> ${JSON.stringify(trimmed)}`,
152+
);
153+
}
154+
return trimmed.endsWith("/") ? trimmed.slice(0, -1) : trimmed;
155+
};
156+
147157
for (const source of redirectFrom) {
148-
const normalized = source.endsWith("/") ? source.slice(0, -1) : source;
158+
const normalized = normalizeRedirectSource(source);
149159
const existing = sourceToFiles.get(normalized);
150160
if (existing) {
151161
existing.push(file);

0 commit comments

Comments
 (0)