-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
src: fix generation of path objects in Windows #56696
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #56696 +/- ##
=======================================
Coverage 89.21% 89.22%
=======================================
Files 662 662
Lines 191945 191950 +5
Branches 36948 36950 +2
=======================================
+ Hits 171238 171258 +20
+ Misses 13549 13542 -7
+ Partials 7158 7150 -8
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A similar already landed last August: #54653
We should use ToU8StringView()
rather than introducing a new API.
Thanks for the review! However, there is a problem with the u8string approach. Therefore, I provided and used an API to handle wstrings without using ToU8StringView. |
I recommend improving existing solution to fit both cases rather than implementing a new solution. |
What are "both cases" presented here? I am sure that ToU8StringView is not used in current codebase. I don't think that trying hard to use u8string in path is a better way to go.... |
The base branch is still bf59539 , so the associated test seems to be fail. (experimental flag) |
Yes, thank you. |
0697f02
to
cba8830
Compare
I had to rush to write my comments before work. I have rebased and force pushed the file, so please check with CI. I would have liked to have been able to do this beforehand, but I looked over the entire code. Lines 3149 to 3160 in d978610
This was exactly what I was looking for. |
src/node_modules.cc
Outdated
@@ -326,6 +330,22 @@ const BindingData::PackageConfig* BindingData::TraverseParent( | |||
return nullptr; | |||
} | |||
|
|||
#ifdef _WIN32 | |||
std::wstring ConvertToWideString(const std::string& str) { | |||
auto cp = GetACP(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section was copied from node_file.cc, but this GetACP
is particularly important.
As shown in the description, when the Windows locale is changed and executed, if the original UTF-8 code is left here, the strings cannot be handled properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this utility function can be moved to util-inl.h
? so that the same implementation (taking into account GetACP
) is used both here and in node_file.cc
without duplication. I think this is also what @anonrig is requesting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do the same for node_fs, test-fs-cp.mjs will falil...
It is very strange, but I have found that if I run the failed path(utf/~~~) in addition to the test-require-~ , it can be handled correctly.
It may be that the pre or post-process (if there is one) regarding path generation in node_fs is having an effect.
Therefore, this time I confined the implementation within node_modules instead of applying it to the whole system.
The following is the error log when applied to the entire system.
https://github.com/yamachu/node/actions/runs/12941644792/job/36098035649?pr=3#step:7:5033
code diff
yamachu@0041793
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about making cp
a function parameter and use CP_UTF8
in node_file.cc
and GetACP()
here. Does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see.
Do you mean to make these changes?
util-inl.h
#ifdef _WIN32
inline std::wstring ConvertToWideString(const std::string& str, UINT cp) {
int size_needed = MultiByteToWideChar(
cp, 0, &str[0], static_cast<int>(str.size()), nullptr, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(
cp, 0, &str[0], static_cast<int>(str.size()), &wstrTo[0], size_needed);
return wstrTo;
}
#endif // _WIN32
node_file.cc
#define BufferValueToPath(str) \
std::filesystem::path(ConvertToWideString(str.ToString(), CP_UTF8))
I thought that this implementation would certainly have less impact and could be implemented with less code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. FWIW, I'm also ok with this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apply 👍 : ef0ade1
https://github.com/yamachu/node/actions/runs/12933259601/job/36071441238#step:12:16876 Test has passed on SJIS Windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSLGTM
Can you please squash the last 3 commits into the second or everything into one? |
24ac7b9
to
ea943d8
Compare
I squashed and added a test case for the newly found problem. |
ea943d8
to
4ddd7ae
Compare
take a similar approach to node_file and allow the creation of paths code point must be specified to convert from wchar_t to utf8.
4ddd7ae
to
ef0ade1
Compare
fix: #56650
ref: #56657
This PR fixes a problem that caused a segmentation fault in module resolution when creating a require object with multibyte characters in a non-English environment.
Since the issue occurred when generating a std::filesystem::path object, some patches were applied to the changed areas in the following PR.
a7dad43
Since the issue was reproduced only in different locales, such as ja-JP on Windows, I rewrote the locale in the CI of coverage-windows to run the test.
https://github.com/yamachu/node/pull/2/files#diff-29094741d50149aa772b3e577ad509116bad722ad2de85689b6cb2c01e806a46
.github/workflows/coverage-windows.yml
The previous PR did not solve the problem when using unicode, so the process was separated for windows and the path object was generated.
The part where std::filesystem::path is used can be fixed by changing this PR.
The results of the test conducted in a Japanese environment can be seen below.
https://github.com/yamachu/node/actions/runs/12903928231/job/35980111577#step:12:16844