Skip to content

Commit

Permalink
fix: encodeURI the returned filepath directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed Dec 28, 2023
1 parent ce52c4f commit 4fe883e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/astro/src/assets/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export async function getImage(
src: imageURL,
srcSet: {
values: srcSets,
attribute: srcSets.map((srcSet) => `${encodeURI(srcSet.url)} ${srcSet.descriptor}`).join(', '),
attribute: srcSets.map((srcSet) => `${srcSet.url} ${srcSet.descriptor}`).join(', '),
},
attributes:
service.getHTMLAttributes !== undefined
Expand Down
6 changes: 4 additions & 2 deletions packages/astro/src/assets/vite-plugin-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ export default function assets({
});
}

// The paths here are used for URLs, so we need to make sure they have the proper format for an URL
// (leading slash, prefixed with the base / assets prefix, encoded, etc)
if (settings.config.build.assetsPrefix) {
return joinPaths(settings.config.build.assetsPrefix, finalFilePath);
return encodeURI(joinPaths(settings.config.build.assetsPrefix, finalFilePath));
} else {
return prependForwardSlash(joinPaths(settings.config.base, finalFilePath));
return encodeURI(prependForwardSlash(joinPaths(settings.config.base, finalFilePath)));
}
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import imageWithSpaces from "../assets/image 1.jpg";
In this example, only two images should be generated :
- The base image
- The 2x image
- The image path should replace ' ' with '%20' in srcset
Additionally, the image URL should be encoded to avoid issues with spaces and other special characters.
-->
<Image src={imageWithSpaces} width={imageWithSpaces.width / 2} widths={[imageWithSpaces.width]} alt="" />
</div>

0 comments on commit 4fe883e

Please sign in to comment.