Grep currently special-cased empty pattern file to be the same as
pattern file with one empty line (empty pattern). That does mirror how
GNU grep behaves, except when -x is provided. In that case .* pattern
needs to be used instead.
Signed-off-by: Gray Wolf <wolf@wolfsden.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
if (option_mask32 & OPT_f) {
load_regexes_from_file(fopt);
if (!pattern_head) { /* -f EMPTY_FILE? */
- /* GNU grep treats it as "nothing matches" */
- llist_add_to(&pattern_head, new_grep_list_data((char*) "", 0));
+ /* GNU grep treats it as "nothing matches" except when -x */
+ const char *data = (option_mask32 & OPT_x) ? ".*" : "";
+ llist_add_to(&pattern_head, new_grep_list_data((char*)data, 0));
invert_search ^= 1;
}
}
"" \
"test\n"
+testing "grep -vxf EMPTY_FILE" \
+ "grep -vxf input" \
+ "test\n" \
+ "" \
+ "test\n"
+
testing "grep -Fw matches only words" \
"grep -Fw foo input" \
"" \