fs.cpSync / fs.cp / fs.promises.cp fails when src/dest args are Buffer
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
Version
All
Platform
All
Subsystem
fs
What steps will reproduce the bug?
const { cpSync, cp, promises } = require('node:fs');
cpSync(Buffer.from('dirA'), Buffer.from('dirB'), { recursive: true, filter(...args) { console.log(...args); return true; } }); // throws
cp(Buffer.from('dirA'), Buffer.from('dirB'), { recursive: true, filter(...args) { console.log(...args); return true; } }, (err) => {
console.log(err); // errors
});
promises.cp(Buffer.from('dirA'), Buffer.from('dirB'), { recursive: true, filter(...args) { console.log(...args); return true; } }); // rejects
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
It should just work without throwing. The filter function should be called with the option to receive the path as either a string, Buffer, or URL.
What do you see instead?
It throws.
Additional information
The issue here is that the underlying implementation assumes that the paths are strings and tries to use the path.join function to concatenate them, which obviously does not work for Buffer and URL. The implementation has to be able to support Buffer and URL paths in order to properly support arbitrary text encodings in file names etc. Unfortunately, because of the way the callback is designed, it's not clear that there is an immediate non-breaking fix ready available.
@dario-piotrowicz @cjihrig @anonrig
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the fs.cpSync, fs.cp, and fs.promises.cp entry points and reproduce the Buffer-path example from the issue. Trace the path handling and filter callback arguments for string, Buffer, and URL inputs. Done means all three APIs accept Buffer and URL paths without throwing, and the filter receives a supported path value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100