| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8156738 commit 206e353
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1634,7 +1634,7 @@ static void RmSync(const FunctionCallbackInfo<Value>& args) { | |||
| 1634 | 1634 | ToNamespacedPath(env, &path); | |
| 1635 | 1635 | THROW_IF_INSUFFICIENT_PERMISSIONS( | |
| 1636 | 1636 | env, permission::PermissionScope::kFileSystemWrite, path.ToStringView()); | |
| 1637 | - auto file_path = std::filesystem::path(path.ToStringView()); | ||
| 1637 | + auto file_path = path.ToPath(); | ||
| 1638 | 1638 | std::error_code error; | |
| 1639 | 1639 | auto file_status = std::filesystem::symlink_status(file_path, error); | |
| 1640 | 1640 | ||
@@ -1649,8 +1649,7 @@ static void RmSync(const FunctionCallbackInfo<Value>& args) { | |||
| 1649 | 1649 | // File is a directory and recursive is false | |
| 1650 | 1650 | if (file_status.type() == std::filesystem::file_type::directory && | |
| 1651 | 1651 | !recursive) { | |
| 1652 | - return THROW_ERR_FS_EISDIR( | ||
| 1653 | - isolate, "Path is a directory: %s", file_path.c_str()); | ||
| 1652 | + return THROW_ERR_FS_EISDIR(isolate, "Path is a directory: %s", path); | ||
| 1654 | 1653 | } | |
| 1655 | 1654 | ||
| 1656 | 1655 | // Allowed errors are: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const tmpdir = require('../common/tmpdir'); | ||
| 4 | + const assert = require('node:assert'); | ||
| 5 | + const fs = require('node:fs'); | ||
| 6 | + const path = require('node:path'); | ||
| 7 | + | ||
| 8 | + // This test ensures that fs.rmSync handles non-ASCII characters in file paths, | ||
| 9 | + // and that errors contain correctly encoded paths and err.path values. | ||
| 10 | + | ||
| 11 | + tmpdir.refresh(); // Prepare a clean temporary directory | ||
| 12 | + | ||
| 13 | + // Define paths with non-ASCII characters | ||
| 14 | + const dirPath = path.join(tmpdir.path, '速_dir'); | ||
| 15 | + const filePath = path.join(tmpdir.path, '速.txt'); | ||
| 16 | + | ||
| 17 | + // Create a directory and a file with non-ASCII characters | ||
| 18 | + fs.mkdirSync(dirPath); | ||
| 19 | + fs.writeFileSync(filePath, 'This is a test file with special characters.'); | ||
| 20 | + fs.rmSync(filePath); | ||
| 21 | + assert.strictEqual(fs.existsSync(filePath), false); | ||
| 22 | + | ||
| 23 | + // Ensure rmSync throws an error when trying to remove a directory without recursive | ||
| 24 | + assert.throws(() => { | ||
| 25 | + fs.rmSync(dirPath, { recursive: false }); | ||
| 26 | + }, (err) => { | ||
| 27 | + // Assert the error code and check that the error message includes the correct non-ASCII path | ||
| 28 | + assert.strictEqual(err.code, 'ERR_FS_EISDIR'); | ||
| 29 | + assert(err.message.includes(dirPath), 'Error message should include the directory path'); | ||
| 30 | + assert.strictEqual(err.path, dirPath); | ||
| 31 | + return true; | ||
| 32 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments