|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Refs: https://github.com/nodejs/node/issues/58634 |
| 4 | +// Refs: https://github.com/nodejs/node/issues/58869 |
| 5 | + |
| 6 | +const common = require('../common'); |
| 7 | + |
| 8 | +if (!common.isLinux) { |
| 9 | + common.skip('This test is only applicable to Linux'); |
| 10 | +} |
| 11 | + |
| 12 | +const { ok, strictEqual } = require('assert'); |
| 13 | +const { join } = require('path'); |
| 14 | +const path = require('path'); |
| 15 | +const tmpdir = require('../common/tmpdir'); |
| 16 | +const { |
| 17 | + cpSync, |
| 18 | + existsSync, |
| 19 | + mkdirSync, |
| 20 | + writeFileSync, |
| 21 | + readFileSync, |
| 22 | +} = require('fs'); |
| 23 | +tmpdir.refresh(); |
| 24 | + |
| 25 | +const tmpdirPath = Buffer.from(join(tmpdir.path, 'a', 'c')); |
| 26 | +const sepBuf = Buffer.from(path.sep); |
| 27 | + |
| 28 | +mkdirSync(tmpdirPath, { recursive: true }); |
| 29 | + |
| 30 | +// The name is the Shift-JIS encoded version of こんにちは世界, |
| 31 | +// or "Hello, World" in Japanese. On Linux systems, this name is |
| 32 | +// a valid path name and should be handled correctly by the copy |
| 33 | +// operation. However, the implementation of cp makes the assumption |
| 34 | +// that the path names are UTF-8 encoded, so while we can create the |
| 35 | +// file and check its existence using a Buffer, the recursive cp |
| 36 | +// operation will fail because it tries to interpret every file name |
| 37 | +// as UTF-8. |
| 38 | +const name = Buffer.from([ |
| 39 | + 0x82, 0xB1, 0x82, 0xF1, 0x82, 0xC9, 0x82, |
| 40 | + 0xBF, 0x82, 0xCD, 0x90, 0x6C, 0x8C, 0x8E, |
| 41 | +]); |
| 42 | +const testPath = Buffer.concat([tmpdirPath, sepBuf, name]); |
| 43 | + |
| 44 | +writeFileSync(testPath, 'test content'); |
| 45 | +ok(existsSync(testPath)); |
| 46 | +strictEqual(readFileSync(testPath, 'utf8'), 'test content'); |
| 47 | + |
| 48 | +// The cpSync is expected to fail because the implementation does not |
| 49 | +// properly handle non-UTF8 names in the path. |
| 50 | + |
| 51 | +cpSync(join(tmpdir.path, 'a'), join(tmpdir.path, 'b'), { |
| 52 | + recursive: true, |
| 53 | + filter: common.mustCall(() => true, 1), |
| 54 | +}); |
0 commit comments