+12
@@ -76,6 +76,8 @@ func scanMultilineLiteralString(b []byte) ([]byte, []byte, error) {
|
|||||||
// mll-char = %x09 / %x20-26 / %x28-7E / non-ascii
|
// mll-char = %x09 / %x20-26 / %x28-7E / non-ascii
|
||||||
// mll-quotes = 1*2apostrophe
|
// mll-quotes = 1*2apostrophe
|
||||||
for i := 3; i < len(b); {
|
for i := 3; i < len(b); {
|
||||||
|
switch b[i] {
|
||||||
|
case '\'':
|
||||||
if scanFollowsMultilineLiteralStringDelimiter(b[i:]) {
|
if scanFollowsMultilineLiteralStringDelimiter(b[i:]) {
|
||||||
i += 3
|
i += 3
|
||||||
|
|
||||||
@@ -101,6 +103,16 @@ func scanMultilineLiteralString(b []byte) ([]byte, []byte, error) {
|
|||||||
|
|
||||||
return b[:i], b[i:], nil
|
return b[:i], b[i:], nil
|
||||||
}
|
}
|
||||||
|
case '\r':
|
||||||
|
if len(b) < i+2 {
|
||||||
|
return nil, nil, newDecodeError(b[len(b):], `need a \n after \r`)
|
||||||
|
}
|
||||||
|
if b[i+1] != '\n' {
|
||||||
|
return nil, nil, newDecodeError(b[i:i+2], `need a \n after \r`)
|
||||||
|
}
|
||||||
|
i += 2 // skip the \n
|
||||||
|
continue
|
||||||
|
}
|
||||||
size := utf8ValidNext(b[i:])
|
size := utf8ValidNext(b[i:])
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
return nil, nil, newDecodeError(b[i:i+1], "invalid character")
|
return nil, nil, newDecodeError(b[i:i+1], "invalid character")
|
||||||
|
|||||||
+10
-2
@@ -571,7 +571,7 @@ func TestUnmarshal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "multiline basic string with windows newline",
|
desc: "multiline basic string with windows newline",
|
||||||
input: "A = \"\"\"\r\nTest\"\"\"",
|
input: "A = \"\"\"\r\nTe\r\nst\"\"\"",
|
||||||
gen: func() test {
|
gen: func() test {
|
||||||
type doc struct {
|
type doc struct {
|
||||||
A string
|
A string
|
||||||
@@ -579,7 +579,7 @@ func TestUnmarshal(t *testing.T) {
|
|||||||
|
|
||||||
return test{
|
return test{
|
||||||
target: &doc{},
|
target: &doc{},
|
||||||
expected: &doc{A: "Test"},
|
expected: &doc{A: "Te\r\nst"},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -2652,6 +2652,14 @@ world'`,
|
|||||||
desc: `carriage return inside literal string`,
|
desc: `carriage return inside literal string`,
|
||||||
data: "A = '\r'",
|
data: "A = '\r'",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: `carriage return inside multiline literal string`,
|
||||||
|
data: "a='''\r'''",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: `carriage return at trail of multiline literal string`,
|
||||||
|
data: "a='''\r",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: `carriage return in comment`,
|
desc: `carriage return in comment`,
|
||||||
data: "# this is a test\ra=1",
|
data: "# this is a test\ra=1",
|
||||||
|
|||||||
Reference in New Issue
Block a user