From 17dbc670186188ba418a1c8842d9349ee557fa2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=B3=B0=E5=AE=81?= Date: Fri, 23 Sep 2022 02:33:28 +0800 Subject: [PATCH] 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 --- .changeset/pink-beans-cross.md | 5 +++++ packages/astro/src/core/util.ts | 2 +- .../\346\265\213\350\257\225/package.json" | 8 +++++++ .../src/pages/index.astro" | 1 + packages/astro/test/non-ascii-path.test.js | 21 +++++++++++++++++++ pnpm-lock.yaml | 6 ++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .changeset/pink-beans-cross.md create mode 100644 "packages/astro/test/fixtures/non-ascii-path/\346\265\213\350\257\225/package.json" create mode 100644 "packages/astro/test/fixtures/non-ascii-path/\346\265\213\350\257\225/src/pages/index.astro" create mode 100644 packages/astro/test/non-ascii-path.test.js diff --git a/.changeset/pink-beans-cross.md b/.changeset/pink-beans-cross.md new file mode 100644 index 000000000000..c56c41b28c0d --- /dev/null +++ b/.changeset/pink-beans-cross.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix slashes for paths containing non-ASCII characters on Windows diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 17fbc41a69d6..07b087493d73 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -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/`; diff --git "a/packages/astro/test/fixtures/non-ascii-path/\346\265\213\350\257\225/package.json" "b/packages/astro/test/fixtures/non-ascii-path/\346\265\213\350\257\225/package.json" new file mode 100644 index 000000000000..0c38763be0da --- /dev/null +++ "b/packages/astro/test/fixtures/non-ascii-path/\346\265\213\350\257\225/package.json" @@ -0,0 +1,8 @@ +{ + "name": "@test/non-ascii-path", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git "a/packages/astro/test/fixtures/non-ascii-path/\346\265\213\350\257\225/src/pages/index.astro" "b/packages/astro/test/fixtures/non-ascii-path/\346\265\213\350\257\225/src/pages/index.astro" new file mode 100644 index 000000000000..57b148ac226b --- /dev/null +++ "b/packages/astro/test/fixtures/non-ascii-path/\346\265\213\350\257\225/src/pages/index.astro" @@ -0,0 +1 @@ +

测试 OK

\ No newline at end of file diff --git a/packages/astro/test/non-ascii-path.test.js b/packages/astro/test/non-ascii-path.test.js new file mode 100644 index 000000000000..5fb947e9e079 --- /dev/null +++ b/packages/astro/test/non-ascii-path.test.js @@ -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'); + }); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ace0a7208698..4b516d159e76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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:*