diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2016-08-08 18:02:43 -0400 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2016-08-17 10:51:07 -0700 |
commit | 116596a4e6ce105994d0c304d289d14c56259162 (patch) | |
tree | 41e9d4c5a1970f548a6bae71d59d44e489ddbaf6 /objectivec/GPBUtilities.m | |
parent | 62f2ff86b58f4d8d82516812a4b20429ad255ab2 (diff) | |
download | protobuf-116596a4e6ce105994d0c304d289d14c56259162.tar.gz protobuf-116596a4e6ce105994d0c304d289d14c56259162.tar.bz2 protobuf-116596a4e6ce105994d0c304d289d14c56259162.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.m | 10 |
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; } } |