Skip to content
Myr

Treat a single-character delimiter as a plain string delimiter

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

even if it's a regular expression meta-character Close #4170

authored by Junegunn Choi · committed by Junegunn Choi · parent 9a6e557 · Browse files · 3 files+18 added−5 removed
This commit

State

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

Diff stats

3 files+18 added−5 removed

  • other:+18 added−5 removed

3 files+18 added−5 removed

modified:src/options_test.go+6 added-2 removed
7 unmodified lines
8 "github.com/junegunn/fzf/src/tui"9)1011func TestDelimiterRegex(t *testing.T) {12 // Valid regex12 // Valid regex, but a single character -> string13 delim := delimiterRegexp(".")14 if delim.regex == nil || delim.str != nil {14 if delim.regex != nil || *delim.str != "." {15 t.Error(delim)16 }17 delim = delimiterRegexp("|")18 if delim.regex != nil || *delim.str != "|" {19 t.Error(delim)20 }21 // Broken regex -> string22 delim = delimiterRegexp("[0-9")23 if delim.regex != nil || *delim.str != "[0-9" {24 t.Error(delim)
482 unmodified lines
modified:src/options.go+8 added-3 removed
753 unmodified lines
754func delimiterRegexp(str string) Delimiter {755 // Special handling of \t756 str = strings.ReplaceAll(str, "\\t", "\t")757758 // 1. Pattern is a single character759 if len([]rune(str)) == 1 {760 return Delimiter{str: &str}761 }762758 // 1. Pattern does not contain any special character763 // 2. Pattern does not contain any special character764 if regexp.QuoteMeta(str) == str {765 return Delimiter{str: &str}766 }767768 rx, e := regexp.Compile(str)764 // 2. Pattern is not a valid regular expression769 // 3. Pattern is not a valid regular expression770 if e != nil {771 return Delimiter{str: &str}772 }773769 // 3. Pattern as regular expression. Slow.774 // 4. Pattern as regular expression. Slow.775 return Delimiter{regex: rx}776}777778func isAlphabet(char uint8) bool {
2406 unmodified lines
modified:CHANGELOG.md+4 added
57 unmodified lines
58 fzf --tmux border-native --bind 'enter:execute:less {}'59 ```60- Added `toggle-multi-line` action61- Added `toggle-hscroll` action62- A single-character delimiter is now treated as a plain string delimiter rather than a regular expression delimiter, even if it's a regular expression meta-character.63 - This means you can just write `--delimiter '|'` instead of escaping it as `--delimiter '\|'`64- Bug fixes65- Bug fixes in fish scripts (thanks to @bitraid)66670.57.068------69- You can now resize the preview window by dragging the border
2326 unmodified lines