diff options
author | 2023-03-07 19:00:34 +0100 | |
---|---|---|
committer | 2023-03-07 13:00:34 -0500 | |
commit | e58a92527f54cb29d3515d544fad833a5ce1061d (patch) | |
tree | c9e4c9b85a05d7227c2957c9363d5c0271b2a85a | |
parent | fbab73c96e9cecc23eff7e78a5d919b0aa8ec2cf (diff) | |
download | astro-e58a92527f54cb29d3515d544fad833a5ce1061d.tar.gz astro-e58a92527f54cb29d3515d544fad833a5ce1061d.tar.zst astro-e58a92527f54cb29d3515d544fad833a5ce1061d.zip |
[@astrojs/image] Handle missing trailing slash in processStaticImage (#6421)
The code path changed by this commit isn't only taken when running using Vite. If the site is configured with a base url which is different from `/` but does **not** end with `/` (for example, because `trailingSlash` is set to `never`), the `- 1` results in an off-by-one error when truncating the URL.
By checking if the base url ends with `/`, we can determine the right length for the prefix to truncate.
-rw-r--r-- | .changeset/eleven-mugs-flash.md | 5 | ||||
-rw-r--r-- | packages/integrations/image/src/build/ssg.ts | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/.changeset/eleven-mugs-flash.md b/.changeset/eleven-mugs-flash.md new file mode 100644 index 000000000..e733a9ff0 --- /dev/null +++ b/.changeset/eleven-mugs-flash.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Handle missing trailing slash in processStaticImage diff --git a/packages/integrations/image/src/build/ssg.ts b/packages/integrations/image/src/build/ssg.ts index 076144282..bf0f7460b 100644 --- a/packages/integrations/image/src/build/ssg.ts +++ b/packages/integrations/image/src/build/ssg.ts @@ -138,7 +138,7 @@ export async function ssgBuild({ // Vite will prefix a hashed image with the base path, we need to strip this // off to find the actual file relative to /dist if (config.base && src.startsWith(config.base)) { - src = src.substring(config.base.length - 1); + src = src.substring(config.base.length - +config.base.endsWith('/')); } if (isRemoteImage(src)) { |