Skip to content

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

Closed
Yeaseen wants to merge 18 commits into
nodejs:mainfrom
Yeaseen:fix-non-ascii-filepath-issue
Closed

fs: fix rmSync to handle non-ASCII characters#56117
Yeaseen wants to merge 18 commits into
nodejs:mainfrom
Yeaseen:fix-non-ascii-filepath-issue

Conversation

@Yeaseen

@Yeaseen Yeaseen commented Dec 3, 2024

Copy link
Copy Markdown
Contributor

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
Comment thread test/parallel/test-fs-rmSync-special-char.js Outdated
Comment thread test/parallel/test-fs-rmSync-special-char.js Outdated
Comment thread test/parallel/test-fs-rmSync-special-char.js Outdated
Comment thread test/parallel/test-fs-rmSync-special-char.js Outdated
Comment thread test/parallel/test-fs-rmSync-special-char.js Outdated

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

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

@codecov

codecov Bot commented Dec 3, 2024

Copy link
Copy Markdown

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

Comment thread src/node_file.cc Outdated
@jazelly

jazelly commented Dec 5, 2024

Copy link
Copy Markdown
Member

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 commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

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

@Yeaseen

Yeaseen commented Dec 6, 2024

Copy link
Copy Markdown
Contributor Author

@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.

Comment thread src/node_file.cc
@Yeaseen

Yeaseen commented Dec 7, 2024

Copy link
Copy Markdown
Contributor Author

@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.

@jazelly jazelly removed the needs-ci PRs that need a full CI run. label Dec 11, 2024
Comment thread src/node_file.cc Outdated
Comment thread test/parallel/test-fs-rmSync-special-char.js
@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
Copy Markdown
Collaborator

@anonrig anonrig left a comment

Copy link
Copy Markdown
Member

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

joyeecheung commented Jan 23, 2025

Copy link
Copy Markdown
Member

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

jasnell commented Jan 23, 2025

Copy link
Copy Markdown
Member

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

@aduh95

aduh95 commented Jan 23, 2025

Copy link
Copy Markdown
Contributor

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

lemire commented Jan 23, 2025

Copy link
Copy Markdown
Member

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

Yeaseen commented Jan 23, 2025

Copy link
Copy Markdown
Contributor Author

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

@lemire

lemire commented Jan 23, 2025

Copy link
Copy Markdown
Member

@Yeaseen

I thought it was a simple fix.

Famous last words. 😄

@Yeaseen

Yeaseen commented Jan 28, 2025

Copy link
Copy Markdown
Contributor Author

@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

Yeaseen commented Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
Collaborator

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

Yeaseen commented Feb 6, 2025

Copy link
Copy Markdown
Contributor Author

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