From eec5ad0c7d304ad0f2d155303b41086e1930227c Mon Sep 17 00:00:00 2001 From: Tom Thumb <74577069+asdfjkalsdfla@users.noreply.github.com> Date: Sun, 14 Jan 2024 16:23:49 -0500 Subject: [PATCH 1/3] fix for url encode slash in path --- packages/astro/src/core/render/params-and-props.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/core/render/params-and-props.ts b/packages/astro/src/core/render/params-and-props.ts index 3532c5f83726..2caf1f243ee9 100644 --- a/packages/astro/src/core/render/params-and-props.ts +++ b/packages/astro/src/core/render/params-and-props.ts @@ -64,7 +64,7 @@ function getRouteParams(route: RouteData, pathname: string): Params | undefined if (route.params.length) { // The RegExp pattern expects a decoded string, but the pathname is encoded // when the URL contains non-English characters. - const paramsMatch = route.pattern.exec(decodeURIComponent(pathname)); + const paramsMatch = route.pattern.exec(decodeURI(pathname)); if (paramsMatch) { return getParams(route.params)(paramsMatch); } From 5ddec501c4b0b920ee9bac520f6a1001a807e7e9 Mon Sep 17 00:00:00 2001 From: Tom Thumb <74577069+asdfjkalsdfla@users.noreply.github.com> Date: Sun, 14 Jan 2024 16:32:58 -0500 Subject: [PATCH 2/3] add unit test --- packages/astro/test/ssr-params.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/astro/test/ssr-params.test.js b/packages/astro/test/ssr-params.test.js index b15955a9faf4..c1884e6067ab 100644 --- a/packages/astro/test/ssr-params.test.js +++ b/packages/astro/test/ssr-params.test.js @@ -39,6 +39,18 @@ describe('Astro.params in SSR', () => { }); }); + describe('Encoded slash in the URL', () => { + it('Encoded slashes are passed to param', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/users/houston/1%2F2food'); + const response = await app.render(request); + expect(response.status).to.equal(200); + const html = await response.text(); + const $ = cheerio.load(html); + expect($('.category').text()).to.equal('1%2F2food'); + }); + }); + it('No double URL decoding', async () => { const app = await fixture.loadTestAdapterApp(); const request = new Request('http://example.com/users/houston/%25'); From b0a2a4b659afc6c5dacfec053a507991474e2fcf Mon Sep 17 00:00:00 2001 From: Tom Thumb <74577069+asdfjkalsdfla@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:12:27 -0500 Subject: [PATCH 3/3] add additonal unit test --- .../ssr-params/src/pages/[category].astro | 2 + packages/astro/test/ssr-params.test.js | 54 ++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/astro/test/fixtures/ssr-params/src/pages/[category].astro b/packages/astro/test/fixtures/ssr-params/src/pages/[category].astro index bdaa1f965d22..390160f75427 100644 --- a/packages/astro/test/fixtures/ssr-params/src/pages/[category].astro +++ b/packages/astro/test/fixtures/ssr-params/src/pages/[category].astro @@ -1,5 +1,6 @@ --- const { category } = Astro.params +const pairing = Astro.url.searchParams.get('pairing')! || ''; --- @@ -8,5 +9,6 @@ const { category } = Astro.params

Testing

{ category }

+

{ pairing }

diff --git a/packages/astro/test/ssr-params.test.js b/packages/astro/test/ssr-params.test.js index c1884e6067ab..d7eebe0d5013 100644 --- a/packages/astro/test/ssr-params.test.js +++ b/packages/astro/test/ssr-params.test.js @@ -39,7 +39,7 @@ describe('Astro.params in SSR', () => { }); }); - describe('Encoded slash in the URL', () => { + describe('Encoded URI components in param', () => { it('Encoded slashes are passed to param', async () => { const app = await fixture.loadTestAdapterApp(); const request = new Request('http://example.com/users/houston/1%2F2food'); @@ -49,6 +49,58 @@ describe('Astro.params in SSR', () => { const $ = cheerio.load(html); expect($('.category').text()).to.equal('1%2F2food'); }); + + it('Encoded ands are passed into the URL param', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/users/houston/food%20%26%20drink'); + const response = await app.render(request); + expect(response.status).to.equal(200); + const html = await response.text(); + const $ = cheerio.load(html); + expect($('.category').text()).to.equal('food %26 drink'); + }); + + it('Encoded hashes are included in param', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/users/houston/food%23drink'); + const response = await app.render(request); + expect(response.status).to.equal(200); + const html = await response.text(); + const $ = cheerio.load(html); + expect($('.category').text()).to.equal('food%23drink'); + }); + + it('Encoded questions are passed in params', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/users/houston/food%3Fpairing%3Ddrink'); + const response = await app.render(request); + expect(response.status).to.equal(200); + const html = await response.text(); + const $ = cheerio.load(html); + expect($('.category').text()).to.equal('food%3Fpairing%3Ddrink'); + }); + + it('Encoded questions arent read as a url params', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/users/houston/food%3Fpairing%3Ddrink'); + const response = await app.render(request); + expect(response.status).to.equal(200); + const html = await response.text(); + const $ = cheerio.load(html); + expect($('.pairing').text()).to.equal(''); + }); + + it('Encoded commas are passed in params ', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/users/houston/food%3Fpairing%3Ddrink%2Csleep'); + const response = await app.render(request); + expect(response.status).to.equal(200); + const html = await response.text(); + const $ = cheerio.load(html); + expect($('.category').text()).to.equal('food%3Fpairing%3Ddrink%2Csleep'); + expect($('.pairing').text()).to.equal(''); + }); + }); it('No double URL decoding', async () => {