aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--objectivec/GPBCodedInputStream.m7
-rw-r--r--objectivec/Tests/GPBCodedInputStreamTests.m11
2 files changed, 9 insertions, 9 deletions
diff --git a/objectivec/GPBCodedInputStream.m b/objectivec/GPBCodedInputStream.m
index eaa28e50..319ec15b 100644
--- a/objectivec/GPBCodedInputStream.m
+++ b/objectivec/GPBCodedInputStream.m
@@ -219,15 +219,16 @@ NSString *GPBCodedInputStreamReadRetainedString(
result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
length:size
encoding:NSUTF8StringEncoding];
+ state->bufferPos += size;
if (!result) {
- result = @"";
#ifdef DEBUG
// https://developers.google.com/protocol-buffers/docs/proto#scalar
- NSLog(@"UTF8 failure, is some field type 'string' when it should be "
+ NSLog(@"UTF-8 failure, is some field type 'string' when it should be "
@"'bytes'?");
#endif
+ [NSException raise:NSParseErrorException
+ format:@"Invalid UTF-8 for a 'string'"];
}
- state->bufferPos += size;
}
return result;
}
diff --git a/objectivec/Tests/GPBCodedInputStreamTests.m b/objectivec/Tests/GPBCodedInputStreamTests.m
index b40360eb..cc402156 100644
--- a/objectivec/Tests/GPBCodedInputStreamTests.m
+++ b/objectivec/Tests/GPBCodedInputStreamTests.m
@@ -283,16 +283,15 @@
[output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
[output flush];
- NSData* data =
+ NSData *data =
[rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ NSError *error = nil;
TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
extensionRegistry:nil
- error:NULL];
- XCTAssertNotNil(message);
- // Make sure we can read string properties twice without crashing.
- XCTAssertEqual([message.defaultString length], (NSUInteger)0);
- XCTAssertEqualObjects(@"", message.defaultString);
+ error:&error];
+ XCTAssertNotNil(error);
+ XCTAssertNil(message);
}
- (void)testBOMWithinStrings {