Skip to content

Commit

Permalink
Set extension regression (gogo#577)
Browse files Browse the repository at this point in the history
* extensionsBytes set extension regression test

* fixed regression from commit 44af720 - using extensionsBytes and doing the following caused GetExtension to return the 'old' value. set -> get -> modify -> set -> get. The 'old' value was not cleared from the byteslice and getting returns the first extension of the given type.
  • Loading branch information
jmarais authored Jun 11, 2019
1 parent 21df5aa commit dadb625
Show file tree
Hide file tree
Showing 5 changed files with 746 additions and 0 deletions.
1 change: 1 addition & 0 deletions proto/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ func ExtensionDescs(pb Message) ([]*ExtensionDesc, error) {
// SetExtension sets the specified extension of pb to the specified value.
func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error {
if epb, ok := pb.(extensionsBytes); ok {
ClearExtension(pb, extension)
newb, err := encodeExtension(extension, value)
if err != nil {
return err
Expand Down
31 changes: 31 additions & 0 deletions test/setextensionbytes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Protocol Buffers for Go with Gadgets
#
# Copyright (c) 2019, The GoGo Authors. All rights reserved.
# http://github.com/gogo/protobuf
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

regenerate:
go install github.com/gogo/protobuf/protoc-gen-gogo
protoc --gogo_out=. --proto_path=../../../../../:../../protobuf/:. *.proto
Loading

0 comments on commit dadb625

Please sign in to comment.