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

Closed
wants to merge 18 commits into 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 53.73134% with 31 lines in your changes missing coverage. Please review.

Project coverage is 89.16%. Comparing base (50d405a) to head (896e117).
Report is 94 commits behind head on main.

Files with missing lines Patch % Lines
src/node_file.cc 51.56% 18 Missing and 13 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56117      +/-   ##
==========================================
- Coverage   89.22%   89.16%   -0.06%     
==========================================
  Files         663      665       +2     
  Lines      191974   192604     +630     
  Branches    36926    37055     +129     
==========================================
+ Hits       171286   171742     +456     
- Misses      13561    13664     +103     
- Partials     7127     7198      +71     
Files with missing lines Coverage Δ
src/api/exceptions.cc 94.18% <100.00%> (ø)
src/node_file.cc 77.16% <51.56%> (-0.07%) ⬇️

... and 48 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: #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

This comment was marked as outdated.

@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

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 22, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 22, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

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

We have Tou8StringView() function thats added in #54653, why don't we use it? I don't see any reason to add a new implementation for this. @joyeecheung @nodejs/cpp-reviewers

@joyeecheung
Copy link
Member

joyeecheung commented Jan 23, 2025

This doesn't add new implementation of the conversion, it just moves existing conversion macros to somewhere earlier so that it can be used in an earlier function. If you want the conversion macros to use ToU8StringView() instead of via wide strings, I think it would be better if you open a separate PR to update these macros. For the purpose of fixing this bug, which has an increasing amount of reports being filed, I think what's done in this PR is adequate, and there is no need to block a bug fix because the existing helper it uses could've been worked better in a separate PR.

@jasnell
Copy link
Member

jasnell commented Jan 23, 2025

I agree with @joyeecheung here. The conversion to use ToU8StringView() can be done separately.

@aduh95
Copy link
Contributor

aduh95 commented Jan 23, 2025

It looks like the CI is failing on Windows:

---
duration_ms: 198.975
exitcode: 1
severity: fail
stack: |-
  node:internal/assert/utils:281
      throw err;
      ^

  AssertionError [ERR_ASSERTION]: Error message should include the path treated as a directory
      at Object.<anonymous> (C:\workspace\node-test-binary-windows-js-suites\node\test\parallel\test-fs-rmSync-special-char.js:41:3)
      at expectedException (node:assert:808:17)
      at expectsError (node:assert:931:3)
      at Function.throws (node:assert:986:3)
      at Object.<anonymous> (C:\workspace\node-test-binary-windows-js-suites\node\test\parallel\test-fs-rmSync-special-char.js:37:8)
      at Module._compile (node:internal/modules/cjs/loader:1738:14)
      at Object..js (node:internal/modules/cjs/loader:1903:10)
      at Module.load (node:internal/modules/cjs/loader:1473:32)
      at Function._load (node:internal/modules/cjs/loader:1285:12)
      at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
    generatedMessage: false,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '=='
  }

  Node.js v24.0.0-pre
...

@lemire
Copy link
Member

lemire commented Jan 23, 2025

It looks like the CI is failing on Windows:

It seems to fail on the additional test that is being added.

@Yeaseen Did you test it under Windows?

@Yeaseen
Copy link
Author

Yeaseen commented Jan 23, 2025

@lemire No. I will be trying this on Windows. I thought it was a simple fix.

@lemire
Copy link
Member

lemire commented Jan 23, 2025

@Yeaseen

I thought it was a simple fix.

Famous last words. 😄

@Yeaseen
Copy link
Author

Yeaseen commented Jan 28, 2025

@joyeecheung I think I figured out the main problem: it was in src/api/exceptions.cc file. I tested both on Windows 11 and Ubuntu 22.04 There's some conflict, making the last few commits messy. Sorry about that.

@Yeaseen
Copy link
Author

Yeaseen commented Feb 5, 2025

@lemire could you please review this and start a CI? I tested this locally, though. Thank you.

@lemire lemire added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 5, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 5, 2025
@nodejs-github-bot
Copy link
Collaborator

@Yeaseen Yeaseen closed this by deleting the head repository Feb 6, 2025
@Yeaseen
Copy link
Author

Yeaseen commented Feb 6, 2025

There's a conflict because some other code already modified what I worked on. I am gonna do this task on a fresh PR

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
10 participants