From a1469efbdd141a26696fdef392334dc337b4d924 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 17 Nov 2017 20:43:47 +0100 Subject: pkg/email: unsplit arguments for test command --- pkg/email/parser.go | 24 +++++++++++++++++- pkg/email/parser_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) (limited to 'pkg') diff --git a/pkg/email/parser.go b/pkg/email/parser.go index 275403960..cbcdc723d 100644 --- a/pkg/email/parser.go +++ b/pkg/email/parser.go @@ -184,9 +184,31 @@ func extractCommand(body []byte) (cmd, args string) { } split := strings.Split(cmdLine, " ") cmd = split[0] + var aargs []string if len(split) > 1 { - args = strings.TrimSpace(strings.Join(split[1:], " ")) + aargs = split[1:] + } + // Text emails are split at 80 columns are the transformation is irrevesible. + // Try to restore args for some commands that don't have spaces in args. + want := 0 + switch cmd { + case "test:": + want = 2 + case "test_5_arg_cmd": + want = 5 + } + for pos := cmdPos + cmdEnd + 1; len(aargs) < want && pos < len(body); { + lineEnd := bytes.IndexByte(body[pos:], '\n') + if lineEnd == -1 { + lineEnd = len(body) - pos + } + line := strings.TrimSpace(string(body[pos : pos+lineEnd])) + if line != "" { + aargs = append(aargs, strings.Split(line, " ")...) + } + pos += lineEnd + 1 } + args = strings.TrimSpace(strings.Join(aargs, " ")) return } diff --git a/pkg/email/parser_test.go b/pkg/email/parser_test.go index ab5fad631..e4e79e253 100644 --- a/pkg/email/parser_test.go +++ b/pkg/email/parser_test.go @@ -10,7 +10,6 @@ import ( "testing" ) -//!!! add tests with \r\n func TestExtractCommand(t *testing.T) { for i, test := range extractCommandTests { t.Run(fmt.Sprint(i), func(t *testing.T) { @@ -142,6 +141,71 @@ line 2 cmd: "", args: "", }, + // This is unfortunate case when a command is split by email client + // due to 80-column limitation. + { + body: ` +#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git +locking/core +`, + cmd: "test:", + args: "git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core", + }, + { + body: ` +#syz test: +git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core +`, + cmd: "test:", + args: "git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core", + }, + { + body: ` +#syz test: +git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git +locking/core +locking/core +`, + cmd: "test:", + args: "git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core", + }, + { + body: ` +#syz test_5_arg_cmd arg1 + + arg2 arg3 + +arg4 +arg5 +`, + cmd: "test_5_arg_cmd", + args: "arg1 arg2 arg3 arg4 arg5", + }, + { + body: ` +#syz test_5_arg_cmd arg1 +arg2`, + cmd: "test_5_arg_cmd", + args: "arg1 arg2", + }, + { + body: ` +#syz test_5_arg_cmd arg1 +arg2 +`, + cmd: "test_5_arg_cmd", + args: "arg1 arg2", + }, + { + body: ` +#syz test_5_arg_cmd arg1 +arg2 + + +`, + cmd: "test_5_arg_cmd", + args: "arg1 arg2", + }, } type ParseTest struct { -- cgit mrf-deployment