Skip to content

Commit 44c957f

Browse files
ktym4aematipico
andauthored
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 <[email protected]>
1 parent a994d60 commit 44c957f

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

.changeset/cool-colts-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@astrojs/markdown-remark": patch
3+
---
4+
5+
Fixes a bug where non-UTF-8 file names are not displayed when using relative paths in markdowns.

packages/astro/test/astro-assets-prefix.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ describe('Assets Prefix - Static', () => {
5151
it('markdown image src start with assetsPrefix', async () => {
5252
const html = await fixture.readFile('/markdown/index.html');
5353
const $ = cheerio.load(html);
54-
const imgAsset = $('img');
55-
expect(imgAsset.attr('src')).to.match(assetsPrefixRegex);
54+
const imgAssets = $('img');
55+
imgAssets.each((i, el) => {
56+
expect(el.attribs.src).to.match(assetsPrefixRegex);
57+
});
5658
});
5759

5860
it('content collections image src start with assetsPrefix', async () => {
Loading

packages/astro/test/fixtures/astro-assets-prefix/src/pages/markdown.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
Relative image has assetsPrefix
44

55
![Relative image](../assets/penguin1.jpg)
6+
7+
![non-UTF-8 file name image](../assets/ペンギン.jpg)

packages/markdown/remark/src/rehype-images.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export function rehypeImages() {
1111
if (node.tagName !== 'img') return;
1212

1313
if (node.properties?.src) {
14+
node.properties.src = decodeURI(node.properties.src);
15+
1416
if (file.data.imagePaths?.has(node.properties.src)) {
1517
const { ...props } = node.properties;
1618

0 commit comments

Comments
 (0)