fs: fix rmSync error messages for non-ASCII paths#61233
fs: fix rmSync error messages for non-ASCII paths#61233Yeaseen wants to merge 1 commit intonodejs:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61233 +/- ##
==========================================
- Coverage 88.54% 88.54% -0.01%
==========================================
Files 704 704
Lines 208738 208736 -2
Branches 40278 40272 -6
==========================================
- Hits 184833 184816 -17
- Misses 15914 15948 +34
+ Partials 7991 7972 -19
🚀 New features to boost your workflow:
|
83b37bd to
a836c7f
Compare
fs.rmSync previously embedded paths directly into custom error messages while also passing the path to ThrowErrnoException. This caused duplicated paths for ASCII names and corrupted paths for non-ASCII directory names on Linux, and inconsistent path formatting on Windows. Remove path concatenation from custom messages and rely on ThrowErrnoException to attach the path safely. Add a test to cover non-ASCII directory names.
a836c7f to
a68d666
Compare
|
8,5/10. Ce document est clair, techniquement précis et facile à comprendre. Sa structure est fluide et explique le problème et sa solution sans détails superflus. Pour atteindre 9 ou 10, il faudrait simplifier légèrement quelques Casino Frumzi phrases ou ajouter une courte phrase de conclusion soulignant l'impact pour les utilisateurs ou les responsables de la maintenance. |
|
Code LGTM, though I am a bit skeptical about the tests - it may not fare well on Windows in the CI or in people's local machines to change the permission this way. Can we use other safer error paths to check it instead? Perhaps the directory not empty one? |
This PR fixes incorrect and inconsistent error messages produced by
fs.rmSyncwhen deletion fails, especially for directories containing non-ASCII characters. The issue affected Linux and Windows differently but shared the same root cause: paths were embedded into custom error messages while also being passed separately toThrowErrnoException.1. Duplicate paths in error messages (Linux, ASCII paths)
fs.rmSyncconstructed messages like:Because
ThrowErrnoExceptionautomatically appends the path, this resulted in duplicated paths when directory names were ASCII-only:2. Corrupted paths for non-ASCII directory names (Linux)
When the directory name contained non-ASCII characters, embedding the path into the message caused UTF-8 bytes to be misinterpreted.
Example:
Here, the first byte of the UTF-8 sequence was interpreted as a Latin-1 character (
é), corrupting the path shown in the error message.3. Inconsistent Windows paths (?\ prefix)
On Windows,
err.pathcould expose raw extended-length paths prefixed with\\?\\, because the platform-specific normalization logic (StringFromPath) was not applied when constructingErrnoException.Example:
This is inconsistent with other fs APIs used in
src/api/exceptions, which strip the prefix before exposing paths to JavaScript.This PR fixes the issue by:
pathargument toThrowErrnoExceptionStringFromPathinsrc/api/exceptionsfor Windows soerr.pathis normalized correctlyA new test has been added:
test-fs-rmSync-special-char-additional-error.jsto verify that:fs.rmSyncreports the correct error codeerr.pathpreserves non-ASCII directory nameserr.messageincludes the correct path@joyeecheung @anonrig Please review this when you are available.