Fix first == npos bug.

This commit is contained in:
2026-08-31 10:15:07 +01:00
parent 24914028c0
commit 4b0f3b8fb7
+3 -1
View File
@@ -18,6 +18,9 @@ void Function::register_extented(BEd &ctx) {
auto path = std::get<std::string>(arg_); auto path = std::get<std::string>(arg_);
const auto first = path.find_first_not_of(" \t"); const auto first = path.find_first_not_of(" \t");
const auto last = path.find_last_not_of(" \t"); const auto last = path.find_last_not_of(" \t");
if (first == std::string::npos)
path.clear();
else
path = path.substr(first, last - first + 1); path = path.substr(first, last - first + 1);
if (path.empty()) if (path.empty())
path = getenv("HOME"); path = getenv("HOME");
@@ -28,7 +31,6 @@ void Function::register_extented(BEd &ctx) {
if (home) if (home)
path = std::string(home) + path.substr(1); path = std::string(home) + path.substr(1);
} }
if (first != std::string::npos)
if (chdir(path.c_str()) == -1) if (chdir(path.c_str()) == -1)
throw ed_error("Can't change directory."); throw ed_error("Can't change directory.");
}, },