Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-beans-cross.md
@@ -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
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, '/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to use slash if we're always doing replace ourselves now?

}

export const VALID_ID_PREFIX = `/@id/`;
Expand Down
@@ -0,0 +1,8 @@
{
"name": "@test/non-ascii-path",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
@@ -0,0 +1 @@
<h1>测试 OK</h1>
21 changes: 21 additions & 0 deletions 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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great looking test!

});
});
});
14 changes: 10 additions & 4 deletions pnpm-lock.yaml

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