mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-15 11:46:58 +00:00
Treat a single-character delimiter as a plain string delimiter
even if it's a regular expression meta-character Close #4170
This commit is contained in:
parent
9a6e557e52
commit
5460517bd2
@ -59,6 +59,10 @@ Also, fzf now offers three "style presets" for easier customization, which can b
|
||||
```
|
||||
- Added `toggle-multi-line` action
|
||||
- Added `toggle-hscroll` action
|
||||
- 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.
|
||||
- This means you can just write `--delimiter '|'` instead of escaping it as `--delimiter '\|'`
|
||||
- Bug fixes
|
||||
- Bug fixes in fish scripts (thanks to @bitraid)
|
||||
|
||||
0.57.0
|
||||
------
|
||||
|
@ -755,18 +755,23 @@ func delimiterRegexp(str string) Delimiter {
|
||||
// Special handling of \t
|
||||
str = strings.ReplaceAll(str, "\\t", "\t")
|
||||
|
||||
// 1. Pattern does not contain any special character
|
||||
// 1. Pattern is a single character
|
||||
if len([]rune(str)) == 1 {
|
||||
return Delimiter{str: &str}
|
||||
}
|
||||
|
||||
// 2. Pattern does not contain any special character
|
||||
if regexp.QuoteMeta(str) == str {
|
||||
return Delimiter{str: &str}
|
||||
}
|
||||
|
||||
rx, e := regexp.Compile(str)
|
||||
// 2. Pattern is not a valid regular expression
|
||||
// 3. Pattern is not a valid regular expression
|
||||
if e != nil {
|
||||
return Delimiter{str: &str}
|
||||
}
|
||||
|
||||
// 3. Pattern as regular expression. Slow.
|
||||
// 4. Pattern as regular expression. Slow.
|
||||
return Delimiter{regex: rx}
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,13 @@ import (
|
||||
)
|
||||
|
||||
func TestDelimiterRegex(t *testing.T) {
|
||||
// Valid regex
|
||||
// Valid regex, but a single character -> string
|
||||
delim := delimiterRegexp(".")
|
||||
if delim.regex == nil || delim.str != nil {
|
||||
if delim.regex != nil || *delim.str != "." {
|
||||
t.Error(delim)
|
||||
}
|
||||
delim = delimiterRegexp("|")
|
||||
if delim.regex != nil || *delim.str != "|" {
|
||||
t.Error(delim)
|
||||
}
|
||||
// Broken regex -> string
|
||||
|
Loading…
Reference in New Issue
Block a user