Skip to content

Commit

Permalink
Fix slashes for paths containing non-ASCII characters on Windows. (#4712
Browse files Browse the repository at this point in the history
)

* Fix slashes for paths containing non-ASCII characters on Windows.

* Add non-ASCII path test

* Fix slashes in pnpm-lock.yaml
  • Loading branch information
Lifeni authored Sep 22, 2022
1 parent e9eb4d1 commit 17dbc67
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/pink-beans-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix slashes for paths containing non-ASCII characters on Windows
2 changes: 1 addition & 1 deletion packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function resolveDependency(dep: string, projectRoot: URL) {
* Windows: C:/Users/astro/code/my-project/src/pages/index.astro
*/
export function viteID(filePath: URL): string {
return slash(fileURLToPath(filePath) + filePath.search);
return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, '/');
}

export const VALID_ID_PREFIX = `/@id/`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/non-ascii-path",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>测试 OK</h1>
21 changes: 21 additions & 0 deletions packages/astro/test/non-ascii-path.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('Non-ASCII Path Test', () => {
let fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/non-ascii-path/测试/' });
await fixture.build();
});

describe('build', () => {
it('Can load page', async () => {
const html = await fixture.readFile(`/index.html`);
const $ = cheerio.load(html);

expect($('h1').text()).to.equal('测试 OK');
});
});
});
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 17dbc67

Please sign in to comment.