fix: use USERPROFILE on Windows for non-ASCII username support#2450
fix: use USERPROFILE on Windows for non-ASCII username support#2450Bhumika-SN wants to merge 2 commits into
Conversation
| public static void clear() { | ||
| depCache = null; | ||
| // Also clear the dependency cache JSON file from disk | ||
| try { |
There was a problem hiding this comment.
This does not seem related to this issue ?
8643349 to
b79bc72
Compare
|
Hi @maxandersen, thank you for the review! You're right — the DependencyCache.java changes belong to a separate |
|
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. |
|
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. |
|
Hi @quintesse and @maxandersen, You're right that the issue was deeper than just Based on quintesse's research in the original issue, the root cause is I've added a second fix: instead of printing the PowerShell setup command Could you please re-review? Thank you! |
|
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)); |
There was a problem hiding this comment.
this does seem right - shouldn't need to write to a tempfile to get UTF_8 string.
There was a problem hiding this comment.
I guess you mean "does not seem right"? (I agree)
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 acorrupted path on Windows when the username contains non-ASCII characters.
Fix
On Windows, prefer
USERPROFILEenvironment variable overuser.homeas it always returns the correct path regardless of username characters.
Related Issue
Fixes #1110