Opened 8 years ago

Closed 7 years ago

#10766 closed Bugs (fixed)

boost::filesystem::path::parent_path() with redundant separator returns wrong value

Reported by: Kolya Kosenko <kolya.kosenko@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc:

Description

boost::filesystem::path::parent_path() function with redundant separator at the end of directory don't return parent directory, it just removes this separator.

Ubuntu 12.04, gcc 4.6.3

Following test fails:

  • test/path_unit_test.cpp

    diff --git test/path_unit_test.cpp test/path_unit_test.cpp
    index 67ccb9f..09c7f34 100644
    namespace  
    662662    CHECK(path("/").parent_path().string() == "");
    663663    CHECK(path("/foo").parent_path().string() == "/");
    664664    CHECK(path("/foo/bar").parent_path().string() == "/foo");
     665    CHECK(path("/foo/bar/").parent_path().string() == "/foo");
    665666
    666667    CHECK(path("/foo/bar/baz.zoo").filename().string() == "baz.zoo");
    667668

Attachments (2)

ticket_10766_fixbug.patch (622 bytes ) - added by Renu Tyagi <renu.tyagi@…> 7 years ago.
Patch for bug.
ticket_10766_fixtest.patch (1.1 KB ) - added by Renu Tyagi <renu.tyagi@…> 7 years ago.
As per my finding Boost considers parent path of /foo/ as /foo and not just /. This is shown in /libs/filesystem/path_test.cpp . But if still it is a bug, then here is the patch for bug and corresponding patch for path_test.cpp.

Download all attachments as: .zip

Change History (3)

by Renu Tyagi <renu.tyagi@…>, 7 years ago

Attachment: ticket_10766_fixbug.patch added

Patch for bug.

by Renu Tyagi <renu.tyagi@…>, 7 years ago

Attachment: ticket_10766_fixtest.patch added

As per my finding Boost considers parent path of /foo/ as /foo and not just /. This is shown in /libs/filesystem/path_test.cpp . But if still it is a bug, then here is the patch for bug and corresponding patch for path_test.cpp.

comment:1 by Beman Dawes, 7 years ago

Resolution: fixed
Status: newclosed

The behavior is correct, so there no bug in that sense.

There is a bug, however, in the sense that the reference documentation is unclear. To fix that, examples and notes have been added to the reference documentation to show why the returned value is in fact correct, and to provide rationale for that behavior. See [path.itr], and [path.decompose] parent_path() and filename() sections of the reference docs.

As a result of those doc changes, this issue is being marked as "fixed" rather than "invalid".

Thanks,

--Beman

Note: See TracTickets for help on using tickets.