Skip to content
Myr

Don't trim last field when delimiter is regex (#4266)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by phanium · committed by GitHub · parent a24d274 · Browse files · 2 files+12 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−1 removed

  • tests:+9 added−0 removed
  • other:+3 added−1 removed

2 files+12 added−1 removed

modified:src/tokenizer.go+3 added-1 removed
223 unmodified lines
224 } else if delimiter.regex != nil {225 locs := delimiter.regex.FindAllStringIndex(str, -1)226 if len(locs) > 0 {227 lastLoc := locs[len(locs)-1]228 if lastLoc[1] == len(str) {228 str = str[:lastLoc[0]]229 str = str[:lastLoc[0]]230 }231 }232 }233 return strings.TrimRightFunc(str, unicode.IsSpace)234}
84 unmodified lines
modified:test/test_core.rb+9 added
1771 unmodified lines
1772 assert_equal ['bar,bar,foo :,:bazfoo'], File.readlines(tempname, chomp: true)1773 end1774 end17751776 def test_accept_nth_regex_delimiter_strip_last1777 tmux.send_keys %((echo "foo:,bar:,baz"; echo "foo:,bar:,baz:,qux:,") | #{FZF} --multi --delimiter='[:,]+' --accept-nth 2.. --sync --bind 'load:select-all+accept' > #{tempname}), :Enter1778 wait do1779 assert_path_exists tempname1780 # Last delimiter and the whitespaces are removed1781 assert_equal ['bar:,baz', 'bar:,baz:,qux'], File.readlines(tempname, chomp: true)1782 end1783 end17841785 def test_accept_nth_template1786 tmux.send_keys %(echo "foo ,bar,baz" | #{FZF} -d, --accept-nth '1st: {1}, 3rd: {3}, 2nd: {2}' --sync --bind start:accept > #{tempname}), :Enter1787 wait do1788 assert_path_exists tempname
5 unmodified lines