summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-04-19 03:34:30 +0430
committerLinus Groh <mail@linusgroh.de>2021-04-19 10:07:58 +0200
commit061aaa33e8069c79a6f12ac06bb9490ed6470848 (patch)
tree5d8b65af9d199744ca5aeb5693e5f61cd677db69 /Userland
parent6e2f2cd8b116b6e06e6bcda094cedf77e6c8c771 (diff)
downloadserenity-061aaa33e8069c79a6f12ac06bb9490ed6470848.zip
Userland/test: Handle '!' being used as a string
e.g. `test ! = !`. Fixes #6465.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/test.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/Userland/Utilities/test.cpp b/Userland/Utilities/test.cpp
index 0cf039e135..9772803cf1 100644
--- a/Userland/Utilities/test.cpp
+++ b/Userland/Utilities/test.cpp
@@ -356,15 +356,6 @@ static OwnPtr<Condition> parse_simple_expression(char* argv[])
fatal_error("Unmatched \033[1m(");
}
- if (arg == "!") {
- if (should_treat_expression_as_single_string(argv[optind]))
- return make<StringCompare>(move(arg), "", StringCompare::NotEqual);
- auto command = parse_complex_expression(argv);
- if (!command)
- fatal_error("Expected an expression after \033[1m!");
- return make<Not>(command.release_nonnull());
- }
-
// Try to read a unary op.
if (arg.starts_with('-') && arg.length() == 2) {
optind++;
@@ -464,6 +455,17 @@ static OwnPtr<Condition> parse_simple_expression(char* argv[])
--optind;
return make<StringCompare>("", lhs, StringCompare::NotEqual);
} else {
+ // Now that we know it's not a well-formed expression, see if it's actually a negation
+ if (lhs == "!") {
+ if (should_treat_expression_as_single_string(arg))
+ return make<StringCompare>(move(lhs), "", StringCompare::NotEqual);
+
+ auto command = parse_complex_expression(argv);
+ if (!command)
+ fatal_error("Expected an expression after \x1b[1m!");
+
+ return make<Not>(command.release_nonnull());
+ }
--optind;
return make<StringCompare>("", lhs, StringCompare::NotEqual);
}