Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@astrojs/image] Handle missing trailing slash in processStaticImage #6421

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[@astrojs/image] Handle missing trailing slash in processStaticImage
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.
  • Loading branch information
vtavernier authored and alixinne committed Mar 4, 2023
commit 67a88000908d21873742ffafd60c7dbcb390fcdc
5 changes: 5 additions & 0 deletions .changeset/eleven-mugs-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---

Handle missing trailing slash in processStaticImage
2 changes: 1 addition & 1 deletion packages/integrations/image/src/build/ssg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down