Skip to content
Myr

Prevent fzf crashing on malformed remote action

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

authored by Junegunn Choi · committed by Junegunn Choi · parent 23d8b78 · Browse files · 1 file+25 added−17 removed
This commit

State

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

Diff stats

1 file+25 added−17 removed

  • other:+25 added−17 removed

1 file+25 added−17 removed

modified:src/options.go+25 added-17 removed
549 unmodified lines
550 return tui.BorderNone551}552553func parseKeyChords(str string, message string) map[tui.Event]string {554 return parseKeyChordsImpl(str, message, errorExit)555}556557func parseKeyChordsImpl(str string, message string, exit func(string)) map[tui.Event]string {558 if len(str) == 0 {555 errorExit(message)559 exit(message)560 return nil561 }562563 str = regexp.MustCompile("(?i)(alt-),").ReplaceAllString(str, "$1"+string([]rune{escapedComma}))564 tokens := strings.Split(str, ",")
125 unmodified lines
690 add(tui.EventType(tui.F1.Int() + int(key[1]) - '1'))691 } else if len(runes) == 1 {692 chords[tui.Key(runes[0])] = key693 } else {689 errorExit("unsupported key: " + key)694 exit("unsupported key: " + key)695 return nil696 }697 }698 }699 return chords
456 unmodified lines
1156 } else {1157 actionArg = spec[offset+1 : len(spec)-1]1158 actions = append(actions, &action{t: t, a: actionArg})1159 }1154 if t == actUnbind || t == actRebind {1155 parseKeyChords(actionArg, spec[0:offset]+" target required")1160 switch t {1161 case actUnbind, actRebind:1162 parseKeyChordsImpl(actionArg, spec[0:offset]+" target required", exit)1163 case actChangePreviewWindow:1164 opts := previewOpts{}1165 for _, arg := range strings.Split(actionArg, "|") {1166 // Make sure that each expression is valid1167 parsePreviewWindowImpl(&opts, arg, exit)1168 }1169 }1170 }1171 }1172 prevSpec = ""
19 unmodified lines
1192 key = tui.Key(',')1193 } else if len(pair[0]) == 1 && pair[0][0] == escapedPlus {1194 key = tui.Key('+')1195 } else {1183 keys := parseKeyChords(pair[0], "key name required")1196 keys := parseKeyChordsImpl(pair[0], "key name required", exit)1197 key = firstKey(keys)1198 }1199 putAllowed := key.Type == tui.Rune && unicode.IsGraphic(key.Char)1200 keymap[key] = parseActionList(pair[1], origPairStr[len(pair[0])+1:], keymap[key], putAllowed, exit)
122 unmodified lines
1323 return infoDefault1324}13251326func parsePreviewWindow(opts *previewOpts, input string) {1327 parsePreviewWindowImpl(opts, input, errorExit)1328}13291330func parsePreviewWindowImpl(opts *previewOpts, input string, exit func(string)) {1331 tokenRegex := regexp.MustCompile(`[:,]*(<([1-9][0-9]*)\(([^)<]+)\)|[^,:]+)`)1332 sizeRegex := regexp.MustCompile("^[0-9]+%?$")1333 offsetRegex := regexp.MustCompile(`^(\+{-?[0-9]+})?([+-][0-9]+)*(-?/[1-9][0-9]*)?$`)1334 headerRegex := regexp.MustCompile("^~(0|[1-9][0-9]*)$")
63 unmodified lines
1398 opts.size = parseSize(token, 99, "window size")1399 } else if offsetRegex.MatchString(token) {1400 opts.scroll = token1401 } else {1385 errorExit("invalid preview window option: " + token)1402 exit("invalid preview window option: " + token)1403 return1404 }1405 }1406 }1407 if len(alternative) > 0 {1408 alternativeOpts := *opts1409 opts.alternative = &alternativeOpts1410 opts.alternative.hidden = false1411 opts.alternative.alternative = nil1394 parsePreviewWindow(opts.alternative, alternative)1412 parsePreviewWindowImpl(opts.alternative, alternative, exit)1413 }1414}14151416func parseMargin(opt string, margin string) [4]sizeSpec {
487 unmodified lines
1904 }1905 }19061907 // Extend the default key map1890 previewEnabled := len(opts.Preview.command) > 0 || hasPreviewAction(opts)1908 keymap := defaultKeymap()1909 for key, actions := range opts.Keymap {1910 var lastChangePreviewWindow *action1911 for _, act := range actions {
2 unmodified lines
1914 // To display "+S"/"-S" on info line1915 opts.ToggleSort = true1916 case actChangePreviewWindow:1917 lastChangePreviewWindow = act1901 if !previewEnabled {1902 // Doesn't matter1903 continue1904 }1905 opts := previewOpts{}1906 for _, arg := range strings.Split(act.a, "|") {1907 // Make sure that each expression is valid1908 parsePreviewWindow(&opts, arg)1909 }1918 }1919 }19201921 // Re-organize actions so that we only keep the last change-preview-window
100 unmodified lines