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

Fix slashes for paths containing non-ASCII characters on Windows. (#4712)

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

* Add non-ASCII path test

* Fix slashes in pnpm-lock.yaml
This commit is contained in:
梁峰宁 2022-09-23 02:33:28 +08:00 committed by GitHub
parent e9eb4d1f3d
commit 17dbc67018
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix slashes for paths containing non-ASCII characters on Windows

View file

@ -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/`;

View file

@ -0,0 +1,8 @@
{
"name": "@test/non-ascii-path",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}

View file

@ -0,0 +1 @@
<h1>测试 OK</h1>

View file

@ -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');
});
});
});

View file

@ -1698,6 +1698,12 @@ importers:
packages/astro/test/fixtures/multiple-renderers/renderers/two:
specifiers: {}
packages/astro/test/fixtures/non-ascii-path/测试:
specifiers:
astro: workspace:*
dependencies:
astro: link:../../../..
packages/astro/test/fixtures/non-html-pages:
specifiers:
astro: workspace:*