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

Conversation

Lifeni
Copy link
Contributor

@Lifeni Lifeni commented Sep 10, 2022

Changes

Related issue: #4689

The slash library cannot handle paths containing non-ASCII characters, so we need to manually replace \ with /.

Examples

fileURLToPath(filePath)
// -> C:\Codes\测试\my-astro-site\src\pages\index.astro

slash(fileURLToPath(filePath))
// -> C:\Codes\测试\my-astro-site\src\pages\index.astro

slash(fileURLToPath(filePath)).replace(/\\/g, '/')
// -> C:/Codes/测试/my-astro-site/src/pages/index.astro ✅

Testing

Test locally only.

Docs

None.

@changeset-bot
Copy link

changeset-bot bot commented Sep 10, 2022

🦋 Changeset detected

Latest commit: cc8a7df

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Sep 10, 2022
@matthewp
Copy link
Contributor

Thanks @Lifeni, can you add a test? If you look in packages/astro/test/fixtures you just create a mini project to test this. Would be wonderful

@Lifeni
Copy link
Contributor Author

Lifeni commented Sep 14, 2022

@matthewp Sorry, I'm new to pull requests and don't have much experience. It seems that I should not merge withastro:main, so what should I do?

pnpm-lock.yaml Outdated
@@ -3225,7 +3231,7 @@ packages:
dependencies:
'@astro-community/astro-embed-twitter': 0.1.3_astro@packages+astro
'@astro-community/astro-embed-youtube': 0.1.1_astro@packages+astro
astro: link:packages/astro
astro: link:packages\astro
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why these changed, can you fix them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I will fix them.

@matthewp
Copy link
Contributor

@Lifeni no need to merge anything. I'll take care of that. If you can just make the updates requested, thanks!

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!

@@ -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?

@matthewp matthewp merged commit 17dbc67 into withastro:main Sep 22, 2022
@astrobot-houston astrobot-houston mentioned this pull request Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants