From 26967e354e030f6a022b7a60a7c9899ec25923aa Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 9 Mar 2021 15:43:49 +0100 Subject: pkg/email: strip \t in test command args There was a precedent of using: syz fix: repo \t commit This was rejected as error. Support \t between tokens. --- pkg/email/parser.go | 9 ++++++--- pkg/email/parser_test.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'pkg') diff --git a/pkg/email/parser.go b/pkg/email/parser.go index df7cc4717..d7bf40a0f 100644 --- a/pkg/email/parser.go +++ b/pkg/email/parser.go @@ -199,7 +199,7 @@ const commandPrefix = "#syz" func extractCommand(body string) (cmd Command, str, args string) { nbody := "\n" + body cmdPos := -1 - for _, delim := range []string{" ", "-", ":"} { + for _, delim := range []string{" ", "\t", "-", ":"} { cmdPos = strings.Index(nbody, "\n"+commandPrefix+delim) if cmdPos != -1 { break @@ -210,7 +210,7 @@ func extractCommand(body string) (cmd Command, str, args string) { return } cmdPos += len(commandPrefix) + 1 - for cmdPos < len(body) && body[cmdPos] == ' ' { + for cmdPos < len(body) && (body[cmdPos] == ' ' || body[cmdPos] == '\t') { cmdPos++ } cmdEnd := strings.IndexByte(body[cmdPos:], '\n') @@ -223,6 +223,9 @@ func extractCommand(body string) (cmd Command, str, args string) { if cmdEnd1 := strings.IndexByte(body[cmdPos:], ' '); cmdEnd1 != -1 && cmdEnd1 < cmdEnd { cmdEnd = cmdEnd1 } + if cmdEnd1 := strings.IndexByte(body[cmdPos:], '\t'); cmdEnd1 != -1 && cmdEnd1 < cmdEnd { + cmdEnd = cmdEnd1 + } str = body[cmdPos : cmdPos+cmdEnd] cmd = strToCmd(str) // Some email clients split text emails at 80 columns are the transformation is irrevesible. @@ -274,7 +277,7 @@ func extractArgsTokens(body string, num int) string { if lineEnd == -1 { lineEnd = len(body) - pos } - line := strings.TrimSpace(body[pos : pos+lineEnd]) + line := strings.TrimSpace(strings.Replace(body[pos:pos+lineEnd], "\t", " ", -1)) for { line1 := strings.Replace(line, " ", " ", -1) if line == line1 { diff --git a/pkg/email/parser_test.go b/pkg/email/parser_test.go index f093a0d22..88b7b4ad9 100644 --- a/pkg/email/parser_test.go +++ b/pkg/email/parser_test.go @@ -220,6 +220,18 @@ locking/core str: "test:", args: "git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core", }, + { + body: `#syz test: repo commit`, + cmd: CmdTest, + str: "test:", + args: "repo commit", + }, + { + body: `#syz test: repo commit`, + cmd: CmdTest, + str: "test:", + args: "repo commit", + }, { body: ` #syz test_5_arg_cmd arg1 @@ -233,6 +245,12 @@ arg5 str: "test_5_arg_cmd", args: "arg1 arg2 arg3 arg4 arg5", }, + { + body: `#syz test_5_arg_cmd arg1 arg2 arg3 arg4 arg5`, + cmd: cmdTest5, + str: "test_5_arg_cmd", + args: "arg1 arg2 arg3 arg4 arg5", + }, { body: ` #syz test_5_arg_cmd arg1 -- cgit mrf-deployment