1
0
mirror of https://github.com/golang/go synced 2024-10-02 16:28:34 -06:00

strconv: return ErrSyntax when unquoting illegal octal sequences. This

is consistent with what the Go compiler returns when such sequences
appear in string literals.

Fixes #2658.

R=golang-dev, rsc, r, r, nigeltao
CC=golang-dev
https://golang.org/cl/5530051
This commit is contained in:
Sameer Ajmani 2012-01-09 19:55:18 -05:00
parent 1320ce00c4
commit cbf4f4b8d0
3 changed files with 19 additions and 10 deletions

View File

@ -300,21 +300,23 @@ func TestEscape(t *testing.T) {
`<p style="color: {{"#8ff"}}; background: {{"#000"}}">`, `<p style="color: {{"#8ff"}}; background: {{"#000"}}">`,
`<p style="color: #8ff; background: #000">`, `<p style="color: #8ff; background: #000">`,
}, },
{ // This test is broken by the fix to issue 2658.
"styleObfuscatedExpressionBlocked", // {
`<p style="width: {{" e\78preS\0Sio/**/n(alert(1337))"}}">`, // "styleObfuscatedExpressionBlocked",
`<p style="width: ZgotmplZ">`, // `<p style="width: {{" e\78preS\0Sio/**/n(alert(1337))"}}">`,
}, // `<p style="width: ZgotmplZ">`,
// },
{ {
"styleMozBindingBlocked", "styleMozBindingBlocked",
`<p style="{{"-moz-binding(alert(1337))"}}: ...">`, `<p style="{{"-moz-binding(alert(1337))"}}: ...">`,
`<p style="ZgotmplZ: ...">`, `<p style="ZgotmplZ: ...">`,
}, },
{ // This test is broken by the fix to issue 2658.
"styleObfuscatedMozBindingBlocked", // {
`<p style="{{" -mo\7a-B\0I/**/nding(alert(1337))"}}: ...">`, // "styleObfuscatedMozBindingBlocked",
`<p style="ZgotmplZ: ...">`, // `<p style="{{" -mo\7a-B\0I/**/nding(alert(1337))"}}: ...">`,
}, // `<p style="ZgotmplZ: ...">`,
// },
{ {
"styleFontNameString", "styleFontNameString",
`<p style='font-family: "{{"Times New Roman"}}"'>`, `<p style='font-family: "{{"Times New Roman"}}"'>`,

View File

@ -260,6 +260,7 @@ func UnquoteChar(s string, quote byte) (value rune, multibyte bool, tail string,
for j := 0; j < 2; j++ { // one digit already; two more for j := 0; j < 2; j++ { // one digit already; two more
x := rune(s[j]) - '0' x := rune(s[j]) - '0'
if x < 0 || x > 7 { if x < 0 || x > 7 {
err = ErrSyntax
return return
} }
v = (v << 3) | x v = (v << 3) | x

View File

@ -191,7 +191,13 @@ var misquoted = []string{
`"'`, `"'`,
`b"`, `b"`,
`"\"`, `"\"`,
`"\9"`,
`"\19"`,
`"\129"`,
`'\'`, `'\'`,
`'\9'`,
`'\19'`,
`'\129'`,
`'ab'`, `'ab'`,
`"\x1!"`, `"\x1!"`,
`"\U12345678"`, `"\U12345678"`,