aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/xml/read_test.go
diff options
context:
space:
mode:
authorLeigh McCulloch <leighmcc@gmail.com>2017-10-27 07:04:57 +0000
committerIan Lance Taylor <iant@golang.org>2017-11-01 20:39:57 +0000
commit14bc4f5e5fd5a113c97bdf1455b4f7d36a81f54b (patch)
tree4dd177f6a897c563194f81738ead79575792e6e2 /src/encoding/xml/read_test.go
parent776cdefc072fc916b5f74a7d7fb6e4573a6c8e89 (diff)
downloadgo-14bc4f5e5fd5a113c97bdf1455b4f7d36a81f54b.tar.gz
go-14bc4f5e5fd5a113c97bdf1455b4f7d36a81f54b.zip
encoding/xml: ignore whitespace in values and attrs
Whitespace is ignored in bool values and attrs. It is convenient and relatively safe since whitespace around a bool value is often unimportant. The same logic can be applied to numeric values of types int, uint, and float. Fixes #22146 Change-Id: Ie0462def90304af144b8e2e72d85b644857c27cc Reviewed-on: https://go-review.googlesource.com/73891 Reviewed-by: Sam Whited <sam@samwhited.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Sam Whited <sam@samwhited.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/encoding/xml/read_test.go')
-rw-r--r--src/encoding/xml/read_test.go118
1 files changed, 116 insertions, 2 deletions
diff --git a/src/encoding/xml/read_test.go b/src/encoding/xml/read_test.go
index 08c3e3b4fe..ba203cd98b 100644
--- a/src/encoding/xml/read_test.go
+++ b/src/encoding/xml/read_test.go
@@ -912,12 +912,50 @@ func TestUnmarshalEmptyValues(t *testing.T) {
type WhitespaceValuesParent struct {
BFalse bool
BTrue bool
+ I int
+ INeg int
+ I8 int8
+ I8Neg int8
+ I16 int16
+ I16Neg int16
+ I32 int32
+ I32Neg int32
+ I64 int64
+ I64Neg int64
+ UI uint
+ UI8 uint8
+ UI16 uint16
+ UI32 uint32
+ UI64 uint64
+ F32 float32
+ F32Neg float32
+ F64 float64
+ F64Neg float64
}
const whitespaceValuesXML = `
<WhitespaceValuesParent>
<BFalse> false </BFalse>
<BTrue> true </BTrue>
+ <I> 266703 </I>
+ <INeg> -266703 </INeg>
+ <I8> 112 </I8>
+ <I8Neg> -112 </I8Neg>
+ <I16> 6703 </I16>
+ <I16Neg> -6703 </I16Neg>
+ <I32> 266703 </I32>
+ <I32Neg> -266703 </I32Neg>
+ <I64> 266703 </I64>
+ <I64Neg> -266703 </I64Neg>
+ <UI> 266703 </UI>
+ <UI8> 112 </UI8>
+ <UI16> 6703 </UI16>
+ <UI32> 266703 </UI32>
+ <UI64> 266703 </UI64>
+ <F32> 266.703 </F32>
+ <F32Neg> -266.703 </F32Neg>
+ <F64> 266.703 </F64>
+ <F64Neg> -266.703 </F64Neg>
</WhitespaceValuesParent>
`
@@ -931,6 +969,25 @@ func TestUnmarshalWhitespaceValues(t *testing.T) {
want := WhitespaceValuesParent{
BFalse: false,
BTrue: true,
+ I: 266703,
+ INeg: -266703,
+ I8: 112,
+ I8Neg: -112,
+ I16: 6703,
+ I16Neg: -6703,
+ I32: 266703,
+ I32Neg: -266703,
+ I64: 266703,
+ I64Neg: -266703,
+ UI: 266703,
+ UI8: 112,
+ UI16: 6703,
+ UI32: 266703,
+ UI64: 266703,
+ F32: 266.703,
+ F32Neg: -266.703,
+ F64: 266.703,
+ F64Neg: -266.703,
}
if v != want {
t.Fatalf("whitespace values: Unmarshal:\nhave: %#+v\nwant: %#+v", v, want)
@@ -938,14 +995,52 @@ func TestUnmarshalWhitespaceValues(t *testing.T) {
}
type WhitespaceAttrsParent struct {
- BFalse bool `xml:",attr"`
- BTrue bool `xml:",attr"`
+ BFalse bool `xml:",attr"`
+ BTrue bool `xml:",attr"`
+ I int `xml:",attr"`
+ INeg int `xml:",attr"`
+ I8 int8 `xml:",attr"`
+ I8Neg int8 `xml:",attr"`
+ I16 int16 `xml:",attr"`
+ I16Neg int16 `xml:",attr"`
+ I32 int32 `xml:",attr"`
+ I32Neg int32 `xml:",attr"`
+ I64 int64 `xml:",attr"`
+ I64Neg int64 `xml:",attr"`
+ UI uint `xml:",attr"`
+ UI8 uint8 `xml:",attr"`
+ UI16 uint16 `xml:",attr"`
+ UI32 uint32 `xml:",attr"`
+ UI64 uint64 `xml:",attr"`
+ F32 float32 `xml:",attr"`
+ F32Neg float32 `xml:",attr"`
+ F64 float64 `xml:",attr"`
+ F64Neg float64 `xml:",attr"`
}
const whitespaceAttrsXML = `
<WhitespaceAttrsParent
BFalse=" false "
BTrue=" true "
+ I=" 266703 "
+ INeg=" -266703 "
+ I8=" 112 "
+ I8Neg=" -112 "
+ I16=" 6703 "
+ I16Neg=" -6703 "
+ I32=" 266703 "
+ I32Neg=" -266703 "
+ I64=" 266703 "
+ I64Neg=" -266703 "
+ UI=" 266703 "
+ UI8=" 112 "
+ UI16=" 6703 "
+ UI32=" 266703 "
+ UI64=" 266703 "
+ F32=" 266.703 "
+ F32Neg=" -266.703 "
+ F64=" 266.703 "
+ F64Neg=" -266.703 "
>
</WhitespaceAttrsParent>
`
@@ -960,6 +1055,25 @@ func TestUnmarshalWhitespaceAttrs(t *testing.T) {
want := WhitespaceAttrsParent{
BFalse: false,
BTrue: true,
+ I: 266703,
+ INeg: -266703,
+ I8: 112,
+ I8Neg: -112,
+ I16: 6703,
+ I16Neg: -6703,
+ I32: 266703,
+ I32Neg: -266703,
+ I64: 266703,
+ I64Neg: -266703,
+ UI: 266703,
+ UI8: 112,
+ UI16: 6703,
+ UI32: 266703,
+ UI64: 266703,
+ F32: 266.703,
+ F32Neg: -266.703,
+ F64: 266.703,
+ F64Neg: -266.703,
}
if v != want {
t.Fatalf("whitespace attrs: Unmarshal:\nhave: %#+v\nwant: %#+v", v, want)