-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
fs: fix rmSync to handle non-ASCII characters #56117
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a2fd236
fs: fix rmSync to handle non-ASCII characters
Yeaseen 3a92727
test: update fs.rmSync test to use tmpdir as per review feedback
Yeaseen f434191
src: use BufferValueToPath for cross-platform path handling
Yeaseen 2572f57
test: fix linter issues in test-fs-rmSync-special-char.js
Yeaseen 8b59d69
test: add more edge cases in test-fs-rmSync-special-char.js
Yeaseen 1d07727
[src] [test] addressed linter issues from CI
Yeaseen fa8ef5a
Merge remote-tracking branch 'upstream/main' into fix-non-ascii-filep…
Yeaseen dc5fd32
addressred reviewrs suggestions
Yeaseen 84f6331
Apply clang-format adjustments to src/node_file.cc
Yeaseen 50f5e96
tests passed on both windows and linux
Yeaseen 70c0a70
resolving conflict
Yeaseen baba1ba
additional changes are done
Yeaseen 7108398
Merge branch 'main' into fix-non-ascii-filepath-issue
Yeaseen 5050b94
Updated src/node_file.cc
Yeaseen 7de5457
conflict avoid
Yeaseen 896e117
addressred linter issue
Yeaseen 7803546
Merge branch 'main' into fix-non-ascii-filepath-issue
Yeaseen 8db36d7
src: use BufferValueToPath for cross-platform path handling
Yeaseen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
| const tmpdir = require('../common/tmpdir'); | ||
| const assert = require('node:assert'); | ||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
|
|
||
| // This test ensures that fs.rmSync handles non-ASCII characters in file paths, | ||
| // and that errors contain correctly encoded paths and err.path values. | ||
|
|
||
| tmpdir.refresh(); // Prepare a clean temporary directory | ||
|
|
||
| // Define paths with non-ASCII characters | ||
| const dirPath = path.join(tmpdir.path, '速_dir'); | ||
| const filePath = path.join(tmpdir.path, '速.txt'); | ||
| const incorrectDirPath = filePath + path.sep; // Treat file as if it were a directory | ||
|
|
||
| // Create a directory and a file with non-ASCII characters | ||
| fs.mkdirSync(dirPath); | ||
| fs.writeFileSync(filePath, 'This is a test file with special characters.'); | ||
|
|
||
| fs.rmSync(filePath); | ||
| assert.strictEqual(fs.existsSync(filePath), false); | ||
|
|
||
| // Ensure rmSync throws an error when trying to remove a directory without recursive | ||
| assert.throws(() => { | ||
| fs.rmSync(dirPath, { recursive: false }); | ||
joyeecheung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, (err) => { | ||
| // Assert the error code and check that the error message includes the correct non-ASCII path | ||
| assert.strictEqual(err.code, 'ERR_FS_EISDIR'); | ||
| assert(err.message.includes(dirPath), 'Error message should include the directory path'); | ||
| assert.strictEqual(err.path, dirPath); | ||
| return true; | ||
| }); | ||
|
|
||
| // Test for not_a_directory error when a file path is incorrectly treated as a directory path | ||
| assert.throws(() => { | ||
| fs.rmSync(incorrectDirPath, { recursive: true }); | ||
| }, (err) => { | ||
| assert.strictEqual(err.code, 'ENOENT'); | ||
| assert(err.message.includes(incorrectDirPath), 'Error message should include the path treated as a directory'); | ||
| return true; | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.