diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2016-08-09 12:32:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-09 12:32:56 -0400 |
commit | 30bbbe99e220cb872f5d6c60f5156233bb408d79 (patch) | |
tree | 8a2d418467e7bcf2985243f90aa1900441f70c56 /objectivec/GPBUtilities.m | |
parent | 237f321e338b50503eb38728afa6ad29bea6076a (diff) | |
parent | 1a6c1d092df6431c86b74a059214ab76942b8b33 (diff) | |
download | protobuf-30bbbe99e220cb872f5d6c60f5156233bb408d79.tar.gz protobuf-30bbbe99e220cb872f5d6c60f5156233bb408d79.tar.bz2 protobuf-30bbbe99e220cb872f5d6c60f5156233bb408d79.zip |
Merge pull request #1934 from thomasvl/objc_strings_with_null
Never use strlen on utf8 runs so null characters work.
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; } } |