Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rf.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ func readLine(text string) (line, rest string, err error) {

case c == '\\':
j := i + 1
if j < len(text) && (text[j] == '\'' || text[j] == '"') {
keep.WriteString(text[start:i])
keep.WriteByte(text[j])
start = j + 1
i = j + 1
continue
}
for j < len(text) && text[j] == ' ' || text[j] == '\t' {
j++
}
Expand Down
24 changes: 24 additions & 0 deletions rf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ var readLineTests = []struct {
in: "cmd {\nx y\n}\n",
out: []string{"cmd {\nx y\n}"},
},
{
in: "cmd It\\'s not a failure\n",
out: []string{"cmd It's not a failure"},
},
{
in: "cmd 'It\\'s not a failure'\n",
out: []string{"cmd 'It\\'s not a failure'"},
},
{
in: "cmd It\\\"s not a failure\n",
out: []string{"cmd It\"s not a failure"},
},
{
in: "cmd \"It\\\"s not a failure\"\n",
out: []string{"cmd \"It\\\"s not a failure\""},
},
{
in: "cmd It's a failure\n",
err: fmt.Errorf("newline in '-quoted string"),
},
{
in: "cmd It\"s a failure\n",
err: fmt.Errorf("newline in \"-quoted string"),
},
}

func TestReadLine(t *testing.T) {
Expand Down
Loading