From 56f83be92a6417bb1cbb88dd58c3dcaf5177b9b6 Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Thu, 1 Sep 2022 20:31:53 +0000 Subject: [PATCH] Fix: [@astrojs/image] handle filenames with spaces (#4593) * fix: decode file URLs to handle filenames with spaces * chore: add changeset --- .changeset/twelve-singers-accept.md | 5 ++++ .../image/src/vite-plugin-astro-image.ts | 3 ++- ...ducing-astro.jpg => introducing astro.jpg} | Bin .../basic-image/src/pages/index.astro | 3 +++ .../integrations/image/test/image-ssg.test.js | 24 ++++++++++++++++++ .../image/test/image-ssr-build.test.js | 12 +++++++++ .../image/test/image-ssr-dev.test.js | 14 ++++++++++ 7 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 .changeset/twelve-singers-accept.md rename packages/integrations/image/test/fixtures/basic-image/src/assets/blog/{introducing-astro.jpg => introducing astro.jpg} (100%) diff --git a/.changeset/twelve-singers-accept.md b/.changeset/twelve-singers-accept.md new file mode 100644 index 000000000..5644d387d --- /dev/null +++ b/.changeset/twelve-singers-accept.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Fixes a bug that broke support for local images with spaces in the filename diff --git a/packages/integrations/image/src/vite-plugin-astro-image.ts b/packages/integrations/image/src/vite-plugin-astro-image.ts index 25945ef9c..f19c557c3 100644 --- a/packages/integrations/image/src/vite-plugin-astro-image.ts +++ b/packages/integrations/image/src/vite-plugin-astro-image.ts @@ -55,7 +55,8 @@ export function createPlugin(config: AstroConfig, options: Required
+ +

diff --git a/packages/integrations/image/test/image-ssg.test.js b/packages/integrations/image/test/image-ssg.test.js index d93f23de8..04d62125d 100644 --- a/packages/integrations/image/test/image-ssg.test.js +++ b/packages/integrations/image/test/image-ssg.test.js @@ -27,6 +27,12 @@ describe('SSG images - dev', function () { url: '/@astroimage/assets/social.jpg', query: { f: 'jpg', w: '506', h: '253' }, }, + { + title: 'Filename with spaces', + id: '#spaces', + url: '/@astroimage/assets/blog/introducing astro.jpg', + query: { f: 'webp', w: '768', h: '414' }, + }, { title: 'Inline imports', id: '#inline', @@ -91,6 +97,12 @@ describe('SSG images with subpath - dev', function () { url: '/@astroimage/assets/social.jpg', query: { f: 'jpg', w: '506', h: '253' }, }, + { + title: 'Filename with spaces', + id: '#spaces', + url: '/@astroimage/assets/blog/introducing astro.jpg', + query: { f: 'webp', w: '768', h: '414' }, + }, { title: 'Inline imports', id: '#inline', @@ -159,6 +171,12 @@ describe('SSG images - build', function () { regex: /^\/social.\w{8}_\w{4,10}.jpg/, size: { width: 506, height: 253, type: 'jpg' }, }, + { + title: 'Filename with spaces', + id: '#spaces', + regex: /^\/introducing astro.\w{8}_\w{4,10}.webp/, + size: { width: 768, height: 414, type: 'webp' }, + }, { title: 'Inline imports', id: '#inline', @@ -217,6 +235,12 @@ describe('SSG images with subpath - build', function () { regex: /^\/docs\/social.\w{8}_\w{4,10}.jpg/, size: { width: 506, height: 253, type: 'jpg' }, }, + { + title: 'Filename with spaces', + id: '#spaces', + regex: /^\/docs\/introducing astro.\w{8}_\w{4,10}.webp/, + size: { width: 768, height: 414, type: 'webp' }, + }, { title: 'Inline imports', id: '#inline', diff --git a/packages/integrations/image/test/image-ssr-build.test.js b/packages/integrations/image/test/image-ssr-build.test.js index 1d45ed234..888397d99 100644 --- a/packages/integrations/image/test/image-ssr-build.test.js +++ b/packages/integrations/image/test/image-ssr-build.test.js @@ -22,6 +22,12 @@ describe('SSR images - build', async function () { url: '/_image', query: { f: 'jpg', w: '506', h: '253', href: /^\/assets\/social.\w{8}.jpg/ }, }, + { + title: 'Filename with spaces', + id: '#spaces', + url: '/_image', + query: { f: 'webp', w: '768', h: '414', href: /^\/assets\/introducing astro.\w{8}.jpg/ }, + }, { title: 'Inline imports', id: '#inline', @@ -105,6 +111,12 @@ describe('SSR images with subpath - build', function () { url: '/_image', query: { f: 'jpg', w: '506', h: '253', href: /^\/docs\/assets\/social.\w{8}.jpg/ }, }, + { + title: 'Filename with spaces', + id: '#spaces', + url: '/_image', + query: { f: 'webp', w: '768', h: '414', href: /^\/docs\/assets\/introducing astro.\w{8}.jpg/ }, + }, { title: 'Inline imports', id: '#inline', diff --git a/packages/integrations/image/test/image-ssr-dev.test.js b/packages/integrations/image/test/image-ssr-dev.test.js index c34973de9..a280268d0 100644 --- a/packages/integrations/image/test/image-ssr-dev.test.js +++ b/packages/integrations/image/test/image-ssr-dev.test.js @@ -32,6 +32,13 @@ describe('SSR images - dev', function () { query: { f: 'jpg', w: '506', h: '253' }, contentType: 'image/jpeg', }, + { + title: 'Filename with spaces', + id: '#spaces', + url: '/@astroimage/assets/blog/introducing astro.jpg', + query: { f: 'webp', w: '768', h: '414' }, + contentType: 'image/webp', + }, { title: 'Inline imports', id: '#inline', @@ -116,6 +123,13 @@ describe('SSR images with subpath - dev', function () { query: { f: 'jpg', w: '506', h: '253' }, contentType: 'image/jpeg', }, + { + title: 'Filename with spaces', + id: '#spaces', + url: '/@astroimage/assets/blog/introducing astro.jpg', + query: { f: 'webp', w: '768', h: '414' }, + contentType: 'image/webp', + }, { title: 'Inline imports', id: '#inline',