0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Fix a bug that Japanese files were not displayed correctly. (#9866)

* Fix: Fix a bug that Japanese files were not displayed correctly.

* chore: generate change description

* Update .changeset/cool-colts-watch.md

* add test case for non-UTF-8 file name

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
ktym4a 2024-01-29 23:42:44 +07:00 committed by GitHub
parent a994d609b3
commit 44c957f893
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/markdown-remark": patch
---
Fixes a bug where non-UTF-8 file names are not displayed when using relative paths in markdowns.

View file

@ -51,8 +51,10 @@ describe('Assets Prefix - Static', () => {
it('markdown image src start with assetsPrefix', async () => {
const html = await fixture.readFile('/markdown/index.html');
const $ = cheerio.load(html);
const imgAsset = $('img');
expect(imgAsset.attr('src')).to.match(assetsPrefixRegex);
const imgAssets = $('img');
imgAssets.each((i, el) => {
expect(el.attribs.src).to.match(assetsPrefixRegex);
});
});
it('content collections image src start with assetsPrefix', async () => {

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -3,3 +3,5 @@
Relative image has assetsPrefix
![Relative image](../assets/penguin1.jpg)
![non-UTF-8 file name image](../assets/ペンギン.jpg)

View file

@ -11,6 +11,8 @@ export function rehypeImages() {
if (node.tagName !== 'img') return;
if (node.properties?.src) {
node.properties.src = decodeURI(node.properties.src);
if (file.data.imagePaths?.has(node.properties.src)) {
const { ...props } = node.properties;