Skip to content

Commit

Permalink
Favor the shortest match
Browse files Browse the repository at this point in the history
Instead of unconditionally returning the length of the current match,
make sure the shortest match bubbles up along the recursive call stack.

Note that this bug only occurs when a choice contains multiple instances
of the query and the right-most match is the shortest one. See the
example below including the choice, query, match prior this commit and
after:

Choice       Query  Before       After
aa/åå/aa/aa  aa/aa  aa/åå/aa/aa  aa/åå/aa/aa
                    ^      ^           ^   ^
                    |------|           |---|
  • Loading branch information
mptre committed Aug 28, 2017
1 parent 50e9645 commit d7d25a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TESTS=tests/01.t tests/02.t tests/03.t tests/04.t tests/05.t tests/06.t \
tests/37.t tests/38.t tests/39.t tests/40.t tests/41.t tests/42.t \
tests/43.t tests/44.t tests/45.t tests/46.t tests/47.t tests/48.t \
tests/49.t tests/50.t tests/51.t tests/52.t tests/53.t tests/54.t \
tests/55.t tests/56.t tests/57.t
tests/55.t tests/56.t tests/57.t tests/58.t
TEST_EXTENSIONS=.t
T_LOG_COMPILER=$(top_srcdir)/tests/pick-test.sh
AM_COLOR_TESTS=no
Expand Down
2 changes: 1 addition & 1 deletion pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ min_match(const char *string, size_t offset, ssize_t *start, ssize_t *end)
*end = e - string;
}

return length;
return *end - *start;
}

/*
Expand Down
7 changes: 7 additions & 0 deletions tests/58.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: it favors the shortest match
keys: aa/aa \n # ENTER
stdin:
aa/åå/aa
aa/åå/aa/aa
stdout:
aa/åå/aa/aa

0 comments on commit d7d25a8

Please sign in to comment.