add sanitization for recallActions, minor binding fix

pull/30/head
Simon Let 6 years ago
parent b2b058e9e2
commit d251dc99f4
  1. 31
      cmd/sanitize/main.go
  2. 2
      scripts/reshctl.sh

@ -173,11 +173,42 @@ func (s *sanitizer) sanitizeRecord(record *records.Record) error {
log.Fatal("Cmd:", record.CmdLine, "; sanitization error:", err)
}
if len(record.RecallActionsRaw) > 0 {
record.RecallActionsRaw, err = s.sanitizeRecallActions(record.RecallActionsRaw)
if err != nil {
log.Fatal("RecallActionsRaw:", record.RecallActionsRaw, "; sanitization error:", err)
}
}
// add a flag to signify that the record has been sanitized
record.Sanitized = true
return nil
}
// sanitizes the recall actions by replacing the recall prefix with it's length
func (s *sanitizer) sanitizeRecallActions(str string) (string, error) {
sanStr := ""
for x, actionStr := range strings.Split(str, ";") {
if x == 0 {
continue
}
if len(actionStr) == 0 {
return str, errors.New("Action can't be empty; idx=" + strconv.Itoa(x))
}
fields := strings.Split(actionStr, ":")
if len(fields) != 2 {
return str, errors.New("Action should have exactly one ':' - encountered:" + actionStr)
}
action := fields[0]
if action != "arrow_up" && action != "arrow_down" {
return str, errors.New("Action (part 1) should be either 'arrow_up' or 'arrow_down' - encountered:" + action)
}
prefix := fields[1]
sanPrefix := strconv.Itoa(len(prefix))
sanStr += ";" + action + ":" + sanPrefix
}
return sanStr, nil
}
func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) {
const optionEndingChars = "\"$'\\#[]!><|;{}()*,?~&=`:@^/+%." // all bash control characters, '=', ...
const optionAllowedChars = "-_" // characters commonly found inside of options

@ -46,7 +46,7 @@ __resh_unbind_arrows() {
echo "Warn: Couldn't revert arrow DOWN binding because 'revert command' is empty."
else
eval "$__RESH_bindfunc_revert_arrow_down_bind"
[ -z "${__RESH_bindfunc_revert_arrow_up_bind_vim+x}" ] || eval "$__RESH_bindfunc_revert_arrow_up_bind_vim"
[ -z "${__RESH_bindfunc_revert_arrow_down_bind_vim+x}" ] || eval "$__RESH_bindfunc_revert_arrow_down_bind_vim"
echo "RESH arrow down binding successfully disabled ✓"
__RESH_arrow_keys_bind_enabled=0
fi

Loading…
Cancel
Save