Skip to content

An empty HOME or XDG_* variable is treated as a value, not as unset #35

Description

@skipbit

Both path::home() and the xdg accessors read an environment variable and branch on whether it is present. An empty string is present, so it wins over the fallback.

home()

src/platform/path.cpp:31 reads HOME through environment::value(), which returns std::optional<std::string>. With HOME="" set, that optional holds "" and has_value() is true, so .or_else() never runs and getpwuid() is never consulted. home() returns path{""}.

xdg

src/platform/xdg.cpp:14 and the three sibling accessors do the same with XDG_CONFIG_HOME and friends. With XDG_CONFIG_HOME="", config_home() returns "myapp" — a relative path in the working directory rather than an absolute one.

The XDG Base Directory specification is explicit here: a variable set to an empty value is to be treated the same as one that is unset.

Effect

A caller who passes the result to path::mkdir() creates directories under the current working directory instead of under the user's home.

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