[php] Added a unit test that bad UTF-8 is rejected in the parser.
PiperOrigin-RevId: 632274113pull/16811/head
parent
b51dc1b438
commit
5a91d6fe5e
|
@ -394,7 +394,8 @@ class Message
|
|||
}
|
||||
break;
|
||||
case GPBType::STRING:
|
||||
// TODO: Add utf-8 check.
|
||||
// We don't check UTF-8 here; that will be validated by the
|
||||
// setter later.
|
||||
if (!GPBWire::readString($input, $value)) {
|
||||
throw new GPBDecodeException(
|
||||
"Unexpected EOF inside string field.");
|
||||
|
|
|
@ -683,6 +683,21 @@ class EncodeDecodeTest extends TestBase
|
|||
$m->mergeFromString(hex2bin('7201'));
|
||||
}
|
||||
|
||||
public function testDecodeInvalidStringDataBadUtf8()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$m = new TestMessage();
|
||||
$m->mergeFromString(hex2bin('720180'));
|
||||
}
|
||||
|
||||
public function testDecodeValidStringData()
|
||||
{
|
||||
$m = new TestMessage();
|
||||
$m->mergeFromString(hex2bin('720161'));
|
||||
$this->assertSame('a', $m->getOptionalString());
|
||||
}
|
||||
|
||||
public function testDecodeInvalidBytesLengthMiss()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
|
|
Loading…
Reference in New Issue