Skip to content

append() drops the parent path when the component starts with two separators #36

Description

@skipbit

src/platform/path.cpp:77 strips one leading separator from the component so that a component written as /name joins rather than replaces:

if (component.substr(0, 1) == path::separator()) {
    p.append(std::string(component).replace(0, 1, ""));
} else {
    p.append(component);
}

One character is not always enough. For a component with two leading slashes, stripping one leaves a string that is still absolute, and std::filesystem::path::append replaces the whole path instead of joining:

append("c")               on "/a/b"  ->  "/a/b/c"
append("/c")              on "/a/b"  ->  "/a/b/c"
append("//c")             on "/a/b"  ->  "/c"
append("//server/share")  on "/a/b"  ->  "/server/share"

Measured on Linux with GCC 13.3.0, so this is reachable today and not specific to any one platform. Stripping every leading separator, rather than one, closes it.

A related case exists only if Windows support is implemented: separator() returns "/" unconditionally, so a component starting with \ never matches the guard, and append treats it as root-relative on Windows. Whether that matters depends on #33.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions