1
0
mirror of https://github.com/json-iterator/go.git synced 2025-05-13 21:36:29 +02:00

fix #274, unescape before base64 decode

This commit is contained in:
Tao Wen 2018-05-26 09:38:52 +08:00
parent 6c702ce12a
commit 37cc313d18
2 changed files with 5 additions and 7 deletions

View File

@ -416,16 +416,11 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
} }
switch iter.WhatIsNext() { switch iter.WhatIsNext() {
case StringValue: case StringValue:
encoding := base64.StdEncoding src := iter.ReadString()
src := iter.SkipAndReturnBytes() dst, err := base64.StdEncoding.DecodeString(src)
src = src[1 : len(src)-1]
decodedLen := encoding.DecodedLen(len(src))
dst := make([]byte, decodedLen)
len, err := encoding.Decode(dst, src)
if err != nil { if err != nil {
iter.ReportError("decode base64", err.Error()) iter.ReportError("decode base64", err.Error())
} else { } else {
dst = dst[:len]
codec.sliceType.UnsafeSet(ptr, unsafe.Pointer(&dst)) codec.sliceType.UnsafeSet(ptr, unsafe.Pointer(&dst))
} }
case ArrayValue: case ArrayValue:

View File

@ -20,5 +20,8 @@ func init() {
}, unmarshalCase{ }, unmarshalCase{
ptr: (*[]byte)(nil), ptr: (*[]byte)(nil),
input: `"aGVsbG8="`, input: `"aGVsbG8="`,
}, unmarshalCase{
ptr: (*[]byte)(nil),
input: `"c3ViamVjdHM\/X2Q9MQ=="`,
}) })
} }