[@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.
This commit is contained in:
parent
fbab73c96e
commit
e58a92527f
2 changed files with 6 additions and 1 deletions
5
.changeset/eleven-mugs-flash.md
Normal file
5
.changeset/eleven-mugs-flash.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/image': patch
|
||||
---
|
||||
|
||||
Handle missing trailing slash in processStaticImage
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue