mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-29 12:17:48 +00:00
internal/impl: make errInvalidUTF8 be a proto.Error
Fixes golang/protobuf#1174. Change-Id: If95f9f79fff76dc0c44f7ee96e484f59fa287e58 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/244718 Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
parent
1ecb1f411c
commit
a0f95d5b14
@ -10,6 +10,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/proto"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
preg "google.golang.org/protobuf/reflect/protoregistry"
|
||||
@ -20,6 +21,7 @@ type errInvalidUTF8 struct{}
|
||||
|
||||
func (errInvalidUTF8) Error() string { return "string field contains invalid UTF-8" }
|
||||
func (errInvalidUTF8) InvalidUTF8() bool { return true }
|
||||
func (errInvalidUTF8) Unwrap() error { return errors.Error }
|
||||
|
||||
// initOneofFieldCoders initializes the fast-path functions for the fields in a oneof.
|
||||
//
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/testing/protopack"
|
||||
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
testpb "google.golang.org/protobuf/internal/testprotos/test"
|
||||
test3pb "google.golang.org/protobuf/internal/testprotos/test3"
|
||||
)
|
||||
@ -82,6 +83,8 @@ func TestDecodeInvalidMessages(t *testing.T) {
|
||||
got := want.ProtoReflect().New().Interface()
|
||||
if err := opts.Unmarshal(test.wire, got); err == nil {
|
||||
t.Errorf("Unmarshal unexpectedly succeeded\ninput bytes: [%x]\nMessage:\n%v", test.wire, prototext.Format(got))
|
||||
} else if !errors.Is(err, proto.Error) {
|
||||
t.Errorf("Unmarshal error is not a proto.Error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
pref "google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
orderpb "google.golang.org/protobuf/internal/testprotos/order"
|
||||
testpb "google.golang.org/protobuf/internal/testprotos/test"
|
||||
test3pb "google.golang.org/protobuf/internal/testprotos/test3"
|
||||
@ -136,6 +137,9 @@ func TestEncodeInvalidMessages(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("Marshal unexpectedly succeeded\noutput bytes: [%x]\nMessage:\n%v", got, prototext.Format(m))
|
||||
}
|
||||
if !errors.Is(err, proto.Error) {
|
||||
t.Fatalf("Marshal error is not a proto.Error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user