Skip to content

Commit

Permalink
Fixed broken tests on pre-go1.8 protocolbuffers#356 (protocolbuffers#359
Browse files Browse the repository at this point in the history
)

Disable benchmarks using testing.B.Run for pre-go1.7.

Fix unmarshaling Any for pre-1.8.  Unmarshaling code for Any assumed
json.RawMessage value receiver on json.Marshaler interface, but it was a
pointer receiver pre-1.8.
  • Loading branch information
cybrcodr authored and dsnet committed May 26, 2017
1 parent 7a211bc commit 63bfc70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions jsonpb/jsonpb.go
Expand Up @@ -624,7 +624,10 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe
// so we don't have to do any extra work.
return u.unmarshalValue(target.Field(0), inputValue, prop)
case "Any":
var jsonFields map[string]json.RawMessage
// Use json.RawMessage pointer type instead of value to support pre-1.8 version.
// 1.8 changed RawMessage.MarshalJSON from pointer type to value type, see
// https://github.com/golang/go/issues/14493
var jsonFields map[string]*json.RawMessage
if err := json.Unmarshal(inputValue, &jsonFields); err != nil {
return err
}
Expand All @@ -635,7 +638,7 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe
}

var turl string
if err := json.Unmarshal([]byte(val), &turl); err != nil {
if err := json.Unmarshal([]byte(*val), &turl); err != nil {
return fmt.Errorf("can't unmarshal Any's '@type': %q", val)
}
target.Field(0).SetString(turl)
Expand All @@ -656,7 +659,7 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe
return errors.New("Any JSON doesn't have 'value'")
}

if err := u.unmarshalValue(reflect.ValueOf(m).Elem(), val, nil); err != nil {
if err := u.unmarshalValue(reflect.ValueOf(m).Elem(), *val, nil); err != nil {
return fmt.Errorf("can't unmarshal Any's WKT: %v", err)
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions proto/decode_test.go
Expand Up @@ -29,6 +29,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// +build go1.7

package proto_test

import (
Expand Down
2 changes: 2 additions & 0 deletions proto/encode_test.go
Expand Up @@ -29,6 +29,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// +build go1.7

package proto_test

import (
Expand Down

0 comments on commit 63bfc70

Please sign in to comment.