Opened 12 years ago

Closed 8 years ago

#4611 closed Bugs (wontfix)

path::operator / does not remove redundant separators

Reported by: neo_in_matrix@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.44.0 Severity: Optimization
Keywords: Cc:

Description

The following code produces path3 as \abc
def\, which is not expected.

filesystem::path path1("\\abc\\");
filesystem::path path2("\\def\\");
filesystem::path path3 = path1 / path2;

Though the OS level API can handle duplicate path seps correctly, but it is not considered good practice to return path strings like this.

Change History (3)

comment:1 by neo_in_matrix@…, 12 years ago

BTW, I have #define BOOST_FILESYSTEM_VERSION 3 so that I am using the newer version 3 of filesystem.hpp.

comment:2 by neo_in_matrix@…, 12 years ago

Yeah... my first message is garbled by this bug system.

Let's say the code is like this:

filesystem::path path1("\\abc\\");
filesystem::path path2("\\xyz\\");
filesystem::path path3 = path1 / path2;
//path3 will be \abc\\xyz\, which has redundant path seps.

comment:3 by Beman Dawes, 8 years ago

Resolution: wontfix
Status: newclosed

See http://cplusplus.github.io/filesystem-ts/working-draft.html#path-appends

The ISO C++ filesystem TS says:

Appends path::preferred_separator to pathname unless:

  • an added separator would be redundant, or
  • would change a relative path to an absolute path [Note: An empty path is relative. — end note], or
  • p.empty(), or
  • *p.native().cbegin() is a directory separator.

Then appends p.native() to pathname.

Boost.Filesystem follows the TS here. The TS does not add a separator if it would be redundant, but if native() ends with a separator and the append argument begins with a separator, both are retained.

You are free to report this to the C++ committee as defect, and if they decide to change the spec then Boost.Filesystem will follow their lead. But I'm not aware of any reason for adding a gratuitous difference between Boost and other implementation.

Thanks for your interest in Boost.Filesystem,

--Beman

PS: Test case added to verify the library works as expected per your test case.

Note: See TracTickets for help on using tickets.