Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
f3f5b3fb
Commit
f3f5b3fb
authored
Apr 05, 2016
by
Thomas Van Lenten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests to ensure we read strings with BOMs so we don't forget about lessons of the past.
parent
89719f07
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
GPBCodedInputStreamTests.m
objectivec/Tests/GPBCodedInputStreamTests.m
+38
-0
No files found.
objectivec/Tests/GPBCodedInputStreamTests.m
View file @
f3f5b3fb
...
...
@@ -295,4 +295,42 @@
XCTAssertEqualObjects
(
@""
,
message
.
defaultString
);
}
-
(
void
)
testBOMWithinStrings
{
// We've seen servers that end up with BOMs within strings (not always at the
// start, and sometimes in multiple places), make sure they always parse
// correctly. (Again, this is inpart incase a custom string class is ever
// used again.)
const
char
*
strs
[]
=
{
"
\xEF\xBB\xBF
String with BOM"
,
"String with
\xEF\xBB\xBF
in middle"
,
"String with end bom
\xEF\xBB\xBF
"
,
"
\xEF\xBB\xBF\xe2\x99\xa1
"
,
// BOM White Heart
"
\xEF\xBB\xBF\xEF\xBB\xBF
String with Two BOM"
,
};
for
(
size_t
i
=
0
;
i
<
GPBARRAYSIZE
(
strs
);
++
i
)
{
NSOutputStream
*
rawOutput
=
[
NSOutputStream
outputStreamToMemory
];
GPBCodedOutputStream
*
output
=
[
GPBCodedOutputStream
streamWithOutputStream
:
rawOutput
];
int32_t
tag
=
GPBWireFormatMakeTag
(
TestAllTypes_FieldNumber_DefaultString
,
GPBWireFormatLengthDelimited
);
[
output
writeRawVarint32
:
tag
];
size_t
length
=
strlen
(
strs
[
i
]);
[
output
writeRawVarint32
:(
int32_t
)
length
];
[
output
writeRawData
:[
NSData
dataWithBytes
:
strs
[
i
]
length
:
length
]];
[
output
flush
];
NSData
*
data
=
[
rawOutput
propertyForKey
:
NSStreamDataWrittenToMemoryStreamKey
];
GPBCodedInputStream
*
input
=
[
GPBCodedInputStream
streamWithData
:
data
];
TestAllTypes
*
message
=
[
TestAllTypes
parseFromCodedInputStream
:
input
extensionRegistry
:
nil
error
:
NULL
];
XCTAssertNotNil
(
message
,
@"Loop %zd"
,
i
);
// Ensure the string is there. NSString can consume the BOM in some
// cases, so don't actually check the string for exact equality.
XCTAssertTrue
(
message
.
defaultString
.
length
>
0
,
@"Loop %zd"
,
i
);
}
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment