Skip to content

fix: use USERPROFILE on Windows for non-ASCII username support#2450

Open
Bhumika-SN wants to merge 2 commits into
jbangdev:mainfrom
Bhumika-SN:fix/windows-non-ascii-username-path
Open

fix: use USERPROFILE on Windows for non-ASCII username support#2450
Bhumika-SN wants to merge 2 commits into
jbangdev:mainfrom
Bhumika-SN:fix/windows-non-ascii-username-path

Conversation

@Bhumika-SN
Copy link
Copy Markdown
Contributor

Problem

On Windows, users with non-ASCII characters in their username (common
in many countries including India, China, Eastern Europe) experience
broken PATH setup and jbang failing completely.

Root cause: Java's System.getProperty("user.home") can return a
corrupted path on Windows when the username contains non-ASCII characters.

Fix

On Windows, prefer USERPROFILE environment variable over user.home
as it always returns the correct path regardless of username characters.

Related Issue

Fixes #1110

public static void clear() {
depCache = null;
// Also clear the dependency cache JSON file from disk
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This does not seem related to this issue ?

@Bhumika-SN Bhumika-SN force-pushed the fix/windows-non-ascii-username-path branch from 8643349 to b79bc72 Compare May 2, 2026 02:43
@Bhumika-SN
Copy link
Copy Markdown
Contributor Author

Hi @maxandersen, thank you for the review!

You're right — the DependencyCache.java changes belong to a separate
PR for the cache clear issue. I have rebased this branch to only
include the USERPROFILE fix for the non-ASCII username issue.

@Bhumika-SN Bhumika-SN requested a review from maxandersen May 2, 2026 16:47
@maxandersen maxandersen requested a review from quintesse May 8, 2026 13:05
@maxandersen
Copy link
Copy Markdown
Collaborator

it makes sense afaics; @quintesse do you see any issue using this as default on windows as it seems the jdk is not changing it afaics.

@quintesse
Copy link
Copy Markdown
Contributor

I don't know, this is really hard to test so how do we know this works?

If you look at the original issue I did quite a bit of research all those years ago and it definitely seemed to be more than just a user home issue, it was any path that had weird characters in it.

But right now I can't even reproduce the issue, not with Java 8, nor with 17.

But of course I set my Windows default codepage to UTF8 some time ago (and no, I'm not setting it back just to test :-) too much shit can go wrong on Windows)

Not sure if I still have VM around with Windows on it, I doubt it.

@Bhumika-SN
Copy link
Copy Markdown
Contributor Author

Hi @quintesse and @maxandersen,

You're right that the issue was deeper than just user.home.

Based on quintesse's research in the original issue, the root cause is
that Java's stdout encoding gets corrupted when PowerShell captures it.

I've added a second fix: instead of printing the PowerShell setup command
to stdout, we now write it to a UTF-8 encoded temp file and print the
file path instead. This avoids the encoding corruption entirely.

Could you please re-review? Thank you!

@quintesse
Copy link
Copy Markdown
Contributor

Now that it isn't only the user home, which is hard to test, it would be great if you were able to add a test that shows the issue is fixed. I'll try to come up with one myself, but I first have to find time, so if you were able to provide tests it would speed things up considerably :-)

try {
Path tmpFile = Files.createTempFile("jbang-setup-", ".ps1");
tmpFile.toFile().deleteOnExit();
Files.write(tmpFile, cmd.getBytes(StandardCharsets.UTF_8));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this does seem right - shouldn't need to write to a tempfile to get UTF_8 string.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess you mean "does not seem right"? (I agree)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes. Not right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jbang on PowerShell handles non-ASCII characters in home directory badly

3 participants