Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions tests/Utf8ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testValidUtf8()
}
}

public function testAllErrorTypes()
public function testNotAContinuationOctet()
{
try {
Utf8Validator::validate('"abcd'.chr(233).'"');
Expand All @@ -41,6 +41,19 @@ public function testAllErrorTypes()
$this->assertContains('Non-UTF8 character found', $e->getMessage());
$this->assertContains(' which is not a continuation octet.', $e->getMessage());
}
for ($i = 246; $i < 255; ++$i) { // 245 and 255 already forbidden
try {
Utf8Validator::validate('"abcd'.chr(195).chr($i).'"');
$this->fail('"abcd\d195\d'.$i.'" should not pass validation.');
} catch (InvalidEncodingException $e) {
$this->assertContains('Non-UTF8 character found', $e->getMessage());
$this->assertContains(' which is not a continuation octet.', $e->getMessage());
}
}
}

public function testPrematureEndOfString()
{
try {
Utf8Validator::validate('"abcd'.chr(233));
$this->fail('ISO 8859-15 "abcdé should not pass validation.');
Expand All @@ -51,6 +64,10 @@ public function testAllErrorTypes()
$e->getMessage()
);
}
}

public function testForbiddenOctets()
{
$forbiddenOctets = array(
192,
193,
Expand Down Expand Up @@ -79,6 +96,10 @@ public function testAllErrorTypes()
);
}
}
}

public function testUnwantedContinuationOctet()
{
try {
Utf8Validator::validate('"abcd'.chr(129).'"');
$this->fail('"abcd\d129" should not pass validation.');
Expand All @@ -89,6 +110,10 @@ public function testAllErrorTypes()
$e->getMessage()
);
}
}

public function testForbiddenSurrogatePairs()
{
for ($i = 160; $i <= 191; ++$i) {
try {
Utf8Validator::validate('"abcd'.chr(237).chr($i).chr(129).'"');
Expand All @@ -111,6 +136,10 @@ public function testAllErrorTypes()
);
}
}
}

public function testOtherInvalidOctetSequences()
{
for ($i = 246; $i < 255; ++$i) { // 245 and 255 already forbidden
try {
Utf8Validator::validate('"abcd'.chr($i).chr(129).chr(129).chr(129).'"');
Expand All @@ -126,13 +155,6 @@ public function testAllErrorTypes()
$this->assertContains('Non-UTF8 character found', $e->getMessage());
$this->assertContains(' which is invalid.', $e->getMessage());
}
try {
Utf8Validator::validate('"abcd'.chr(195).chr($i).'"');
$this->fail('"abcd\d195\d'.$i.'" should not pass validation.');
} catch (InvalidEncodingException $e) {
$this->assertContains('Non-UTF8 character found', $e->getMessage());
$this->assertContains(' which is not a continuation octet.', $e->getMessage());
}
}
}

Expand Down