Shell expansion rules say that tilde must be replaced with HOME if it exists and only after that we can look at getpwuid

This commit is contained in:
CREMARENCO Cosmin 2016-08-24 11:42:33 +02:00
parent bb456d342a
commit 9d81f54067

View File

@ -204,7 +204,19 @@ std::string PathImpl::expandImpl(const std::string& path)
++it;
if (it != end && *it == '/')
{
result += homeImpl(); ++it;
const char* homeEnv = getenv("HOME");
if (homeEnv)
{
result += homeEnv;
std::string::size_type resultSize = result.size();
if (resultSize > 0 && result[resultSize - 1] != '/')
result.append("/");
}
else
{
result += homeImpl();
}
++it;
}
else result += '~';
}