mirror of
https://github.com/sheumann/hush.git
synced 2025-02-22 10:29:10 +00:00
grep: fix -w match if first match isn't a word, but second is. Closes 4520
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
6f068904dc
commit
83e49ade57
@ -418,11 +418,13 @@ static int grep_file(FILE *file)
|
|||||||
found = 1;
|
found = 1;
|
||||||
} else {
|
} else {
|
||||||
char c = ' ';
|
char c = ' ';
|
||||||
if (match_at > line || gl->matched_range.rm_so != 0)
|
if (match_at > line || gl->matched_range.rm_so != 0) {
|
||||||
c = match_at[gl->matched_range.rm_so - 1];
|
c = match_at[gl->matched_range.rm_so - 1];
|
||||||
|
}
|
||||||
if (!isalnum(c) && c != '_') {
|
if (!isalnum(c) && c != '_') {
|
||||||
c = match_at[gl->matched_range.rm_eo];
|
c = match_at[gl->matched_range.rm_eo];
|
||||||
if (!c || (!isalnum(c) && c != '_')) {
|
}
|
||||||
|
if (!isalnum(c) && c != '_') {
|
||||||
found = 1;
|
found = 1;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
@ -448,7 +450,6 @@ static int grep_file(FILE *file)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/* If it's non-inverted search, we can stop
|
/* If it's non-inverted search, we can stop
|
||||||
* at first match */
|
* at first match */
|
||||||
if (found && !invert_search)
|
if (found && !invert_search)
|
||||||
|
@ -165,6 +165,12 @@ testing "grep -w word doesn't match wordword" \
|
|||||||
"wordword\n" \
|
"wordword\n" \
|
||||||
""
|
""
|
||||||
|
|
||||||
|
testing "grep -w word match second word" \
|
||||||
|
"grep -w word input" \
|
||||||
|
"bword,word\n""wordb,word\n""bwordb,word\n" \
|
||||||
|
"bword,word\n""wordb,word\n""bwordb,word\n" \
|
||||||
|
""
|
||||||
|
|
||||||
# testing "test name" "commands" "expected result" "file input" "stdin"
|
# testing "test name" "commands" "expected result" "file input" "stdin"
|
||||||
# file input will be file called "input"
|
# file input will be file called "input"
|
||||||
# test can create a file "actual" instead of writing to stdout
|
# test can create a file "actual" instead of writing to stdout
|
||||||
|
Loading…
x
Reference in New Issue
Block a user