aboutsummaryrefslogtreecommitdiff
path: root/python/google/protobuf/internal/type_checkers.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/google/protobuf/internal/type_checkers.py')
-rwxr-xr-xpython/google/protobuf/internal/type_checkers.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/python/google/protobuf/internal/type_checkers.py b/python/google/protobuf/internal/type_checkers.py
index 4a76cd4e..0807e7f7 100755
--- a/python/google/protobuf/internal/type_checkers.py
+++ b/python/google/protobuf/internal/type_checkers.py
@@ -185,6 +185,14 @@ class UnicodeValueChecker(object):
'encoding. Non-UTF-8 strings must be converted to '
'unicode objects before being added.' %
(proposed_value))
+ else:
+ try:
+ proposed_value.encode('utf8')
+ except UnicodeEncodeError:
+ raise ValueError('%.1024r isn\'t a valid unicode string and '
+ 'can\'t be encoded in UTF-8.'%
+ (proposed_value))
+
return proposed_value
def DefaultValue(self):