Skip to content

Commit

Permalink
Merge pull request #824 from y-yamagata/master
Browse files Browse the repository at this point in the history
Fix literal word-regexp.
  • Loading branch information
ggreer authored Nov 27, 2016
2 parents b5e750a + aedd3ef commit fc78c0d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void search_buf(const char *buf, const size_t buf_len,
/* It's a match */
} else {
/* It's not a match */
match_ptr += opts.query_len;
buf_offset = end - buf;
match_ptr += find_skip_lookup[0] - opts.query_len + 1;
buf_offset = match_ptr - buf;
continue;
}
}
Expand Down
40 changes: 40 additions & 0 deletions tests/literal_word_regexp.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Setup:

$ . $TESTDIR/setup.sh
$ echo 'blah abc def' > blah1.txt
$ echo 'abc blah def' > blah2.txt
$ echo 'abc def blah' > blah3.txt
$ echo 'abcblah def' > blah4.txt
$ echo 'abc blahdef' >> blah4.txt
$ echo 'blahx blah' > blah5.txt
$ echo 'abcblah blah blah' > blah6.txt

Match a word of the beginning:

$ ag -wF --column 'blah' blah1.txt
1:1:blah abc def

Match a middle word:

$ ag -wF --column 'blah' blah2.txt
1:5:abc blah def

Match a last word:

$ ag -wF --column 'blah' blah3.txt
1:9:abc def blah

No match:

$ ag -wF --column 'blah' blah4.txt
[1]

Match:

$ ag -wF --column 'blah' blah5.txt
1:7:blahx blah

Case of a word repeating the same part:

$ ag -wF --column 'blah blah' blah6.txt
1:9:abcblah blah blah

0 comments on commit fc78c0d

Please sign in to comment.