From 902290375c49a4e16f05c315e442b479018845d3 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 28 Jun 2025 21:18:44 -0700 Subject: [PATCH 1/2] test: add known issue tests for fs.cp --- test/known_issues/test-fs-cp-async-buffer.js | 21 ++++++++ test/known_issues/test-fs-cp-filter.js | 32 ++++++++++++ test/known_issues/test-fs-cp-non-utf8.js | 51 ++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 test/known_issues/test-fs-cp-async-buffer.js create mode 100644 test/known_issues/test-fs-cp-filter.js create mode 100644 test/known_issues/test-fs-cp-non-utf8.js diff --git a/test/known_issues/test-fs-cp-async-buffer.js b/test/known_issues/test-fs-cp-async-buffer.js new file mode 100644 index 00000000000000..86a11d86429641 --- /dev/null +++ b/test/known_issues/test-fs-cp-async-buffer.js @@ -0,0 +1,21 @@ +'use strict'; + +// We expect this test to fail because the implementation of fsPromise.cp +// does not properly support the use of Buffer as the source or destination +// argument like fs.cpSync does. + +const common = require('../common'); +const { mkdirSync, promises } = require('fs'); +const { join } = require('path'); +const tmpdir = require('../common/tmpdir'); + +tmpdir.refresh(); + +const tmpA = join(tmpdir.path, 'a'); +const tmpB = join(tmpdir.path, 'b'); + +mkdirSync(tmpA, { recursive: true }); + +promises.cp(Buffer.from(tmpA), Buffer.from(tmpB), { + recursive: true, +}).then(common.mustCall()); diff --git a/test/known_issues/test-fs-cp-filter.js b/test/known_issues/test-fs-cp-filter.js new file mode 100644 index 00000000000000..6a060637c219a1 --- /dev/null +++ b/test/known_issues/test-fs-cp-filter.js @@ -0,0 +1,32 @@ +'use strict'; + +// This test will fail because the the implementation does not properly +// handle the case when the `src` or `dest` is a Buffer and the `filter` +// function is utilized when recursively copying directories. + +const common = require('../common'); + +const { + cpSync, + mkdirSync, +} = require('fs'); + +const { + join, +} = require('path'); + +const tmpdir = require('../common/tmpdir'); +tmpdir.refresh(); + +const pathA = join(tmpdir.path, 'a'); +const pathAC = join(pathA, 'c'); +const pathB = join(tmpdir.path, 'b'); +mkdirSync(pathAC, { recursive: true }); + +cpSync(Buffer.from(pathA), Buffer.from(pathB), { + recursive: true, + // This should be called multiple times, once for each file/directory, + // but it's only called once in this test because we're expecting this + // to fail. + filter: common.mustCall(() => true, 1), +}); diff --git a/test/known_issues/test-fs-cp-non-utf8.js b/test/known_issues/test-fs-cp-non-utf8.js new file mode 100644 index 00000000000000..ee736a5751d7ec --- /dev/null +++ b/test/known_issues/test-fs-cp-non-utf8.js @@ -0,0 +1,51 @@ +'use strict'; + +const common = require('../common'); + +if (!common.isLinux) { + common.skip('This test is only applicable to Linux'); +} + +const { ok, strictEqual } = require('assert'); +const { join } = require('path'); +const path = require('path'); +const tmpdir = require('../common/tmpdir'); +const { + cpSync, + existsSync, + mkdirSync, + writeFileSync, + readFileSync, +} = require('fs'); +tmpdir.refresh(); + +const tmpdirPath = Buffer.from(join(tmpdir.path, 'a', 'c')); +const sepBuf = Buffer.from(path.sep); + +mkdirSync(tmpdirPath, { recursive: true }); + +// The name is the Shift-JIS encoded version of こんにちは世界, +// or "Hello, World" in Japanese. On Linux systems, this name is +// a valid path name and should be handled correctly by the copy +// operation. However, the implementation of cp makes the assumption +// that the path names are UTF-8 encoded, so while we can create the +// file and check its existence using a Buffer, the recursive cp +// operation will fail because it tries to interpret every file name +// as UTF-8. +const name = Buffer.from([ + 0x82, 0xB1, 0x82, 0xF1, 0x82, 0xC9, 0x82, + 0xBF, 0x82, 0xCD, 0x90, 0x6C, 0x8C, 0x8E, +]); +const testPath = Buffer.concat([tmpdirPath, sepBuf, name]); + +writeFileSync(testPath, 'test content'); +ok(existsSync(testPath)); +strictEqual(readFileSync(testPath, 'utf8'), 'test content'); + +// The cpSync is expected to fail because the implementation does not +// properly handle non-UTF8 names in the path. + +cpSync(join(tmpdir.path, 'a'), join(tmpdir.path, 'b'), { + recursive: true, + filter: common.mustCall(() => true, 1), +}); From 3339b0ca083cb72a2921f9f733390b62a24f91b4 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 28 Jun 2025 21:21:01 -0700 Subject: [PATCH 2/2] Apply suggestions from code review --- test/known_issues/test-fs-cp-async-buffer.js | 2 ++ test/known_issues/test-fs-cp-filter.js | 2 ++ test/known_issues/test-fs-cp-non-utf8.js | 3 +++ 3 files changed, 7 insertions(+) diff --git a/test/known_issues/test-fs-cp-async-buffer.js b/test/known_issues/test-fs-cp-async-buffer.js index 86a11d86429641..4cbf02414749fe 100644 --- a/test/known_issues/test-fs-cp-async-buffer.js +++ b/test/known_issues/test-fs-cp-async-buffer.js @@ -3,6 +3,8 @@ // We expect this test to fail because the implementation of fsPromise.cp // does not properly support the use of Buffer as the source or destination // argument like fs.cpSync does. +// Refs: https://github.com/nodejs/node/issues/58634 +// Refs: https://github.com/nodejs/node/issues/58869 const common = require('../common'); const { mkdirSync, promises } = require('fs'); diff --git a/test/known_issues/test-fs-cp-filter.js b/test/known_issues/test-fs-cp-filter.js index 6a060637c219a1..d6ac92aebe0e9b 100644 --- a/test/known_issues/test-fs-cp-filter.js +++ b/test/known_issues/test-fs-cp-filter.js @@ -3,6 +3,8 @@ // This test will fail because the the implementation does not properly // handle the case when the `src` or `dest` is a Buffer and the `filter` // function is utilized when recursively copying directories. +// Refs: https://github.com/nodejs/node/issues/58634 +// Refs: https://github.com/nodejs/node/issues/58869 const common = require('../common'); diff --git a/test/known_issues/test-fs-cp-non-utf8.js b/test/known_issues/test-fs-cp-non-utf8.js index ee736a5751d7ec..12c04a4227f6c2 100644 --- a/test/known_issues/test-fs-cp-non-utf8.js +++ b/test/known_issues/test-fs-cp-non-utf8.js @@ -1,5 +1,8 @@ 'use strict'; +// Refs: https://github.com/nodejs/node/issues/58634 +// Refs: https://github.com/nodejs/node/issues/58869 + const common = require('../common'); if (!common.isLinux) {