Skip to content
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

fs: fix rmSync to handle non-ASCII characters #56117

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Yeaseen
Copy link

@Yeaseen Yeaseen commented Dec 3, 2024

This is my first pull request here and I read the contribution guide and commit guide.

Update fs.rmSync in src/node_file.cc to properly handle file paths that include non-ASCII characters. This change prevents crashes and errors when attempting to delete files with international or special characters in their names.

Add a test in test/parallel/test-fs-rmSync-special-char.js to ensure that files with non-ASCII characters can be deleted without issues, covering cases that previously led to unexpected behavior or crashes on certain file systems.

Fixes: #56049

For building the node and running the tests, I used:

./configure --ninja
ninja -C out/Release -j 20

make test-only

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Dec 3, 2024
@Yeaseen Yeaseen force-pushed the fix-non-ascii-filepath-issue branch from 0486aea to f4a6ab5 Compare December 3, 2024 12:44
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM with the linter issues addressed

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.00%. Comparing base (94c327c) to head (1d07727).
Report is 63 commits behind head on main.

Files with missing lines Patch % Lines
src/node_file.cc 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56117      +/-   ##
==========================================
+ Coverage   87.99%   88.00%   +0.01%     
==========================================
  Files         656      656              
  Lines      188929   189137     +208     
  Branches    35968    36013      +45     
==========================================
+ Hits       166253   166456     +203     
- Misses      15831    15841      +10     
+ Partials     6845     6840       -5     
Files with missing lines Coverage Δ
src/node_file.cc 77.42% <66.66%> (+0.05%) ⬆️

... and 39 files with indirect coverage changes

src/node_file.cc Outdated Show resolved Hide resolved
@jazelly
Copy link
Member

jazelly commented Dec 5, 2024

Can you please update your first commit message to follow the guideline, i.e. each line needs to be below 72 chars. Also there are some linting issues in your js test.

Update fs.rmSync to properly handle file paths that include
non-ASCII characters. This change prevents crashes and errors
when attempting to delete files with international or special
characters in their names.

Add a test in test/parallel to ensure that files with non-ASCII
characters can be deleted without issues. This covers cases
that previously caused unexpected behavior or crashes on
certain file systems.

Fixes: nodejs#56049
@Yeaseen Yeaseen force-pushed the fix-non-ascii-filepath-issue branch from 423c7d3 to f434191 Compare December 5, 2024 19:13
@Yeaseen
Copy link
Author

Yeaseen commented Dec 5, 2024

@jazelly I made the updates for the first commit message and linter issues. I think it should be fine now.

@Yeaseen Yeaseen force-pushed the fix-non-ascii-filepath-issue branch from 3931460 to 2572f57 Compare December 6, 2024 08:37
@Yeaseen
Copy link
Author

Yeaseen commented Dec 6, 2024

@jazelly This time a linter issue: I didn't put a newline at the end of the test file. I am learning new things! Thanks for your understanding.

@Yeaseen
Copy link
Author

Yeaseen commented Dec 7, 2024

@jazelly @joyeecheung It's updated based on the review.

@nodejs-github-bot
Copy link
Collaborator

@juanarbol juanarbol added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 9, 2024
@nodejs-github-bot

This comment was marked as duplicate.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@jazelly jazelly removed the needs-ci PRs that need a full CI run. label Dec 11, 2024
src/node_file.cc Outdated
@@ -1637,11 +1686,13 @@ static void RmSync(const FunctionCallbackInfo<Value>& args) {
int recursive = args[2]->IsTrue();
int retryDelay = args[3].As<Int32>()->Value();

auto file_path_as_str = PathToString(file_path);
Copy link
Member

Choose a reason for hiding this comment

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

This can be moved into the branch below to avoid excessive conversion costs.

Copy link
Author

Choose a reason for hiding this comment

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

Moved to the if case.


// Ensure rmSync throws an error when trying to remove a directory without recursive
assert.throws(() => {
fs.rmSync(dirPath, { recursive: false });
Copy link
Member

Choose a reason for hiding this comment

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

This only tests the errors from one special path, there are more errors using the string without converting to UTF8...can you add a test to check the errors thrown from line 1747-1764 in node_file.cc?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah. The conversion wasn't done previously. I added the conversion using PathToString macro. Also, I added a test case in the js for checking not_a_directory error case.

@Yeaseen
Copy link
Author

Yeaseen commented Jan 19, 2025

@joyeecheung Sorry for late update. It was a long winter vacation and my marriage ceremony. Hence the hiatus. I updated the changes you mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs.rmSync('速') crash without throw
8 participants