From 9f6fe6d60667683802ff74d1fa8e34257b6dbd51 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Fri, 13 Sep 2019 02:23:05 +0200 Subject: [PATCH] polish sanitization for the release turn some errors into warnings add some option ending characters --- sanitize-history/resh-sanitize-history.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sanitize-history/resh-sanitize-history.go b/sanitize-history/resh-sanitize-history.go index 32a0262..5ce0581 100644 --- a/sanitize-history/resh-sanitize-history.go +++ b/sanitize-history/resh-sanitize-history.go @@ -179,8 +179,8 @@ func (s *sanitizer) sanitizeRecord(record *common.Record) error { } func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) { - const optionEndingChars = "\"$'\\#[]!><|;{}()*,?~&=`" // all bash control characters and '=' which commonly ends options w/ values - const optionAllowedChars = "-_" // characters commonly found inside of options + const optionEndingChars = "\"$'\\#[]!><|;{}()*,?~&=`:@^/+%." // all bash control characters, '=', ... + const optionAllowedChars = "-_" // characters commonly found inside of options sanCmdLine := "" buff := "" @@ -195,7 +195,7 @@ func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) { switch optionDetected { case true: if unicode.IsSpace(r) || strings.ContainsRune(optionEndingChars, r) { - // whitespace, "=" or ";" ends the option + // whitespace or option ends the option // => add option unsanitized optionDetected = false if len(buff) > 0 { @@ -210,7 +210,8 @@ func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) { if len(buff) > 0 { sanToken, err := s.sanitizeCmdToken(buff) if err != nil { - return cmdLine, err + log.Println("WARN: got error while sanitizing cmdLine:", cmdLine) + // return cmdLine, err } sanCmdLine += sanToken buff = "" @@ -222,12 +223,12 @@ func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) { case false: // split command on all non-letter and non-digit characters if unicode.IsLetter(r) == false && unicode.IsDigit(r) == false { - // TODO: decide if we want to split on "-" and "_" // split token if len(buff) > 0 { sanToken, err := s.sanitizeCmdToken(buff) if err != nil { - return cmdLine, err + log.Println("WARN: got error while sanitizing cmdLine:", cmdLine) + // return cmdLine, err } sanCmdLine += sanToken buff = "" @@ -257,7 +258,8 @@ func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) { // sanitize sanToken, err := s.sanitizeCmdToken(buff) if err != nil { - return cmdLine, err + log.Println("WARN: got error while sanitizing cmdLine:", cmdLine) + // return cmdLine, err } sanCmdLine += sanToken return sanCmdLine, nil @@ -358,7 +360,7 @@ func (s *sanitizer) sanitizeCmdToken(token string) (string, error) { isOtherCharacters = false } } - // I decided that I don't want a special sanitization for numbers + // NOTE: I decided that I don't want a special sanitization for numbers // if isDigits { // return s.hashNumericToken(token), nil // } @@ -368,8 +370,9 @@ func (s *sanitizer) sanitizeCmdToken(token string) (string, error) { if isOtherCharacters { return token, nil } - log.Println("token:", token) - return token, errors.New("cmd token is made of mix of letters or digits and other characters") + log.Println("WARN: cmd token is made of mix of letters or digits and other characters; token:", token) + // return token, errors.New("cmd token is made of mix of letters or digits and other characters") + return s.hashToken(token), errors.New("cmd token is made of mix of letters or digits and other characters") } func (s *sanitizer) sanitizeToken(token string) string {