Userland: Fail Core::find_executable_in_path on empty inputs
Before this patch, `which ""` or `type ""` would say that the empty string is `/usr/local/bin/`. Convert callers to consistently call is_empty() on the returned string while we're at it, to support eventually removing the is_null() String state in the future.
This commit is contained in:
parent
7f9bd34d07
commit
170a7e263c
Notes:
sideshowbarker
2024-07-17 21:43:28 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/170a7e263c7 Pull-request: https://github.com/SerenityOS/serenity/pull/11610
3 changed files with 5 additions and 2 deletions
Userland
|
@ -97,6 +97,9 @@ String DirIterator::next_full_path()
|
|||
|
||||
String find_executable_in_path(String filename)
|
||||
{
|
||||
if (filename.is_empty())
|
||||
return {};
|
||||
|
||||
if (filename.starts_with('/')) {
|
||||
if (access(filename.characters(), X_OK) == 0)
|
||||
return filename;
|
||||
|
|
|
@ -227,7 +227,7 @@ int Shell::builtin_type(int argc, const char** argv)
|
|||
|
||||
// check if its an executable in PATH
|
||||
auto fullpath = Core::find_executable_in_path(command);
|
||||
if (!fullpath.is_null()) {
|
||||
if (!fullpath.is_empty()) {
|
||||
printf("%s is %s\n", command, escape_token(fullpath).characters());
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
args_parser.parse(arguments);
|
||||
|
||||
auto fullpath = Core::find_executable_in_path(filename);
|
||||
if (fullpath.is_null()) {
|
||||
if (fullpath.is_empty()) {
|
||||
warnln("no '{}' in path", filename);
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue