Skip to content

Commit

Permalink
pkg/email: strip \t in test command args
Browse files Browse the repository at this point in the history
There was a precedent of using:
syz fix: repo \t commit
This was rejected as error. Support \t between tokens.
  • Loading branch information
dvyukov committed Mar 9, 2021
1 parent b25a460 commit 26967e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/email/parser.go
Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions pkg/email/parser_test.go
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 26967e3

Please sign in to comment.