Closed Bug 1793773 Opened 2 years ago Closed 2 years ago

IOUtils.createUniqueFile doesn't work on Windows if filename contains colon

Categories

(Toolkit Graveyard :: OS.File, defect)

defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: rnons, Unassigned)

References

Details

I don't know if this is a bug or expected behavior, when the filename contains a colon, createFileUnique doesn't work on Windows.

await IOUtils.createUniqueFile("C:\\mozilla-central", "a:b")
// "C:\\mozilla-central\\a:b"
await IOUtils.createUniqueFile("C:\\mozilla-central", "a:b")
// "C:\\mozilla-central\\a:b-1"

createUniqueFile was called twice, but only one file named a was created.

Windows does not support files with a colon in them. The colon is used as a drive separator:

Barret@THEOBROMA ~ $ mkdir foo

    Directory: C:\Users\Barret

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          2022-10-05 12:36 PM                foo

Barret@THEOBROMA ~ $ cd foo
Barret@THEOBROMA ~\foo $ echo "asdf" > ".\a:b"
Barret@THEOBROMA ~\foo $ dir

    Directory: C:\Users\Barret\foo

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2022-10-05 12:36 PM              0 a
```

This behaviour is as expected.
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → INVALID

The reported behaviour requires sanitizing every input to createUniqueFile() in each usage, where filenames are constructed from strings not directly returned by the underlaying filesystem. It therefore seems plausible to sanitize the input filename automatically, to reduce redundancy and to prevent unexpected errors.

There is already a hardcoded set of invalid characters:
https://searchfox.org/mozilla-central/rev/80e1bfa13c954e6450a13b3cc802d82773eba2e0/xpcom/base/nsCRTGlue.h#139

As we're talking about createUniqueFile here, I think it would seem fine to just automatically replace the problematic characters with _. Callers of createUniqueFile do not care that much about the actual file name being used in the end.

Product: Toolkit → Toolkit Graveyard
You need to log in before you can comment on or make changes to this bug.