Creating a file with a single colon in its name strips the part after the colon from the file name and produces an empty file (on Windows)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
let mut f = File::create("before:after").unwrap();
f.write("test".as_bytes()).unwrap();
f.sync_all().unwrap();
I expected to see this happen:
The file creation produces an error, because file paths cannot contain colons on Windows.
Instead, this happened:
There were no errors. Instead, an empty file named before was created.
Note in particular:
- The file was named
before, despite the requested name beingbefore:after. - The file was empty, despite the fact that the code succesfully wrote some text to it and synchronized the writes to disk.
Other observations:
When the file name contains multiple colons then the file creation does produce an error, as expected.
Meta
rustc --version --verbose:
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-pc-windows-msvc
release: 1.83.0
LLVM version: 19.1.1
Tested on Windows 10 Home version 10.0.19045 Build 19045.
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 by reproducing the Windows behavior from the reported File::create("before:after") example and trace the file-path handling entry point. Done means a single-colon filename returns an error instead of creating a truncated, empty file, with regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100