-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ContainerBase::DeepCopy to not modify the source object.
In the worst case, the source object is a constant (eg a global default instance) and modifying them has undefined behavior. PiperOrigin-RevId: 673402981
- Loading branch information
1 parent
5a68ddd
commit 9fa1f4f
Showing
2 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
# Protocol Buffers - Google's data interchange format | ||
# Copyright 2008 Google Inc. All rights reserved. | ||
# | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file or at | ||
# https://developers.google.com/open-source/licenses/bsd | ||
|
||
"""Unittest for reflection.py, with C++ protos linked in.""" | ||
|
||
import copy | ||
import unittest | ||
|
||
from google.protobuf.internal import testing_refleaks | ||
from google.protobuf.internal import _parameterized | ||
from google.protobuf import unittest_pb2 | ||
from google.protobuf import unittest_proto3_arena_pb2 | ||
|
||
|
||
@_parameterized.named_parameters( | ||
('_proto2', unittest_pb2), ('_proto3', unittest_proto3_arena_pb2) | ||
) | ||
@testing_refleaks.TestCase | ||
class ReflectionTest(unittest.TestCase): | ||
|
||
def testEmptyCompositeContainerDeepCopy(self, message_module): | ||
proto1 = message_module.NestedTestAllTypes( | ||
payload=message_module.TestAllTypes(optional_string='foo') | ||
) | ||
nested2 = copy.deepcopy(proto1.child.repeated_child) | ||
self.assertEqual(0, len(nested2)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters