microsoft / microsoft/STL

<filesystem> Should path::make_preferred collapse directory_separators?

Open
#2,082 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

filesystem LWG issue needed
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

I think this deserves an L[E]WG issue. TL;DR, should it be that:

path p("a////b");
p.make_preferred();
assert(p.string() == "a\\\\\\\\b");

or

path p("a////b");
p.make_preferred();
assert(p.string() == "a\\b");

?

The standard for make_preferred says: http://eel.is/c++draft/fs.class.path#fs.path.modifiers-2

Effects: Each directory-separator of the pathname in the generic format is converted to preferred-separator.

with examples showing /s replaced with \s on Windows. Upon closer inspection, however, directory-separator is defined as any number of directory separator characters. From http://eel.is/c++draft/fs.path.generic

directory-separator:
preferred-separator directory-separator(opt)
fallback-separator fallback-separator(opt)

preferred-separator:
operating system dependent directory separator character

fallback-separator:
/ if preferred-separator is not /

The microsoft/STL implements this by replacing all /s with \s in the path:

https://github.com/microsoft/STL/blob/bd7adb4a932725f60ba096580c415616486ab64c/stl/inc/filesystem#L913

(I probably wrote this code so you know who to blame 😅)

as does Boost:

https://github.com/boostorg/filesystem/blob/87d3c1fd8ab94c188719681ee0bb8f63c2998586/src/path.cpp#L231

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the C++ standard clauses for path::make_preferred and the directory-separator definition, then inspect stl/inc/filesystem at the referenced line and compare Boost's implementation. Determine whether repeated separators should be preserved or collapsed and whether an LWG issue is needed; done means the expected behavior is resolved and documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.