Sanitize input strings that should be a single line

pull/3160/head
Junegunn Choi 1 year ago
parent 618d317803
commit 95a7661bb1
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -248,6 +248,10 @@ func (a previewOpts) sameContentLayout(b previewOpts) bool {
return a.wrap == b.wrap && a.headerLines == b.headerLines return a.wrap == b.wrap && a.headerLines == b.headerLines
} }
func firstLine(s string) string {
return strings.SplitN(s, "\n", 2)[0]
}
// Options stores the values of command-line options // Options stores the values of command-line options
type Options struct { type Options struct {
Fuzzy bool Fuzzy bool
@ -1658,10 +1662,10 @@ func parseOptions(opts *Options, allArgs []string) {
case "--prompt": case "--prompt":
opts.Prompt = nextString(allArgs, &i, "prompt string required") opts.Prompt = nextString(allArgs, &i, "prompt string required")
case "--pointer": case "--pointer":
opts.Pointer = nextString(allArgs, &i, "pointer sign string required") opts.Pointer = firstLine(nextString(allArgs, &i, "pointer sign string required"))
validatePointer = true validatePointer = true
case "--marker": case "--marker":
opts.Marker = nextString(allArgs, &i, "selected sign string required") opts.Marker = firstLine(nextString(allArgs, &i, "selected sign string required"))
validateMarker = true validateMarker = true
case "--sync": case "--sync":
opts.Sync = true opts.Sync = true
@ -1776,10 +1780,10 @@ func parseOptions(opts *Options, allArgs []string) {
} else if match, value := optString(arg, "--prompt="); match { } else if match, value := optString(arg, "--prompt="); match {
opts.Prompt = value opts.Prompt = value
} else if match, value := optString(arg, "--pointer="); match { } else if match, value := optString(arg, "--pointer="); match {
opts.Pointer = value opts.Pointer = firstLine(value)
validatePointer = true validatePointer = true
} else if match, value := optString(arg, "--marker="); match { } else if match, value := optString(arg, "--marker="); match {
opts.Marker = value opts.Marker = firstLine(value)
validateMarker = true validateMarker = true
} else if match, value := optString(arg, "-n", "--nth="); match { } else if match, value := optString(arg, "-n", "--nth="); match {
opts.Nth = splitNth(value) opts.Nth = splitNth(value)

@ -731,6 +731,7 @@ func (t *Terminal) ansiLabelPrinter(str string, color *tui.ColorPair, fill bool)
} }
// Extract ANSI color codes // Extract ANSI color codes
str = firstLine(str)
text, colors, _ := extractColor(str, nil, nil) text, colors, _ := extractColor(str, nil, nil)
runes := []rune(text) runes := []rune(text)
@ -785,6 +786,7 @@ func (t *Terminal) ansiLabelPrinter(str string, color *tui.ColorPair, fill bool)
func (t *Terminal) parsePrompt(prompt string) (func(), int) { func (t *Terminal) parsePrompt(prompt string) (func(), int) {
var state *ansiState var state *ansiState
prompt = firstLine(prompt)
trimmed, colors, _ := extractColor(prompt, state, nil) trimmed, colors, _ := extractColor(prompt, state, nil)
item := &Item{text: util.ToChars([]byte(trimmed)), colors: colors} item := &Item{text: util.ToChars([]byte(trimmed)), colors: colors}

Loading…
Cancel
Save