From 92b80b0760a6d43c22d0a27806834e36512855e2 Mon Sep 17 00:00:00 2001 From: Taylor Schley Date: Wed, 17 Nov 2021 17:15:11 -0600 Subject: [PATCH] fix: check for sourcemap statics --- index.js | 9 ++++++++- test/test.js | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0895749..2bec905 100644 --- a/index.js +++ b/index.js @@ -285,7 +285,14 @@ class I18N { if (extname(ctx.path) !== '') { if (!this.config.redirectTLDS) return next(); const asciiFile = toASCII(basename(ctx.path)); - if (!punycodedTlds.some((tld) => asciiFile.endsWith(`.${tld}`))) + + // do a speciality check for .js.map and .css.map + // since .map is in tlds + if ( + !punycodedTlds.some((tld) => asciiFile.endsWith(`.${tld}`)) || + asciiFile.endsWith('.js.map') || + asciiFile.endsWith('.css.map') + ) return next(); } diff --git a/test/test.js b/test/test.js index 3cb3767..1ffd757 100644 --- a/test/test.js +++ b/test/test.js @@ -550,6 +550,31 @@ test('does not redirect to static paths', async (t) => { t.is(res.status, 200); }); +test('does not redirect to static sourcemap paths', async (t) => { + const app = new Koa(); + const i18n = new I18N({ phrases, directory }); + + app.use(session()); + app.use(i18n.middleware); + app.use(i18n.redirect); + + app.use((ctx) => { + const { locale } = ctx; + ctx.body = { locale }; + ctx.status = 200; + }); + + let res = await request(app.listen()) + .get('/login.css.map') + .set('Cookie', ['locale=es']); + t.is(res.status, 200); + + res = await request(app.listen()) + .get('/login.js.map') + .set('Cookie', ['locale=es']); + t.is(res.status, 200); +}); + test('does not redirect typical domain extension when disabled', async (t) => { const app = new Koa(); const i18n = new I18N({ phrases, directory, redirectTLDS: false });