aboutsummaryrefslogtreecommitdiff
path: root/objectivec/GPBUtilities.m
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-08-08 18:02:43 -0400
committerThomas Van Lenten <thomasvl@google.com>2016-08-09 10:37:16 -0400
commit1a6c1d092df6431c86b74a059214ab76942b8b33 (patch)
tree8a2d418467e7bcf2985243f90aa1900441f70c56 /objectivec/GPBUtilities.m
parent237f321e338b50503eb38728afa6ad29bea6076a (diff)
downloadprotobuf-1a6c1d092df6431c86b74a059214ab76942b8b33.tar.gz
protobuf-1a6c1d092df6431c86b74a059214ab76942b8b33.tar.bz2
protobuf-1a6c1d092df6431c86b74a059214ab76942b8b33.zip
Never use strlen on utf8 runs so null characters work.
Fixes https://github.com/google/protobuf/issues/1933 Add a new test that forces strings into two different implementations from the NSString class cluster to help confirm we're exercising both paths by which CodedOutputStream will extract data from an NSString. Move the old +load test (that was flawed because the behavior really depends on the type of string from the NSString class cluster); into a unittest that targets the specific case we're adding a behavior confirmation on. As a bonus, improve the TextFormat generation of string characters < 0x20.
Diffstat (limited to 'objectivec/GPBUtilities.m')
-rw-r--r--objectivec/GPBUtilities.m10
1 files changed, 9 insertions, 1 deletions
diff --git a/objectivec/GPBUtilities.m b/objectivec/GPBUtilities.m
index ee84fb45..ad876ed4 100644
--- a/objectivec/GPBUtilities.m
+++ b/objectivec/GPBUtilities.m
@@ -1052,7 +1052,15 @@ static void AppendStringEscaped(NSString *toPrint, NSMutableString *destStr) {
case '\'': [destStr appendString:@"\\\'"]; break;
case '\\': [destStr appendString:@"\\\\"]; break;
default:
- [destStr appendFormat:@"%C", aChar];
+ // This differs slightly from the C++ code in that the C++ doesn't
+ // generate UTF8; it looks at the string in UTF8, but escapes every
+ // byte > 0x7E.
+ if (aChar < 0x20) {
+ [destStr appendFormat:@"\\%d%d%d",
+ (aChar / 64), ((aChar % 64) / 8), (aChar % 8)];
+ } else {
+ [destStr appendFormat:@"%C", aChar];
+ }
break;
}
}