Skip to content

Modifies the chr() check to properly handle \u0000 codes in the range… #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Add schema validation: Input Objects must not contain non-nullable circular references (#492)
- Added retrieving query complexity once query has been completed (#316)
- Allow input types to be passed in from variables using \stdClass instead of associative arrays (#535)
- Fixes parsing of string literals of the form \u0000 for code points in the range [128, 255] inclusive

#### v0.13.5
- Fix coroutine executor when using with promise (#486)
Expand Down
3 changes: 0 additions & 3 deletions src/Utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,6 @@ public static function printSafe($var)
*/
public static function chr($ord, $encoding = 'UTF-8')
{
if ($ord <= 255) {
return chr($ord);
}
if ($encoding === 'UCS-4BE') {
return pack('N', $ord);
}
Expand Down
36 changes: 36 additions & 0 deletions tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use stdClass;
use function mb_check_encoding;

class UtilsTest extends TestCase
{
Expand All @@ -20,4 +21,39 @@ public function testAssignThrowsExceptionOnMissingRequiredKey() : void
$this->expectExceptionMessage('Key requiredKey is expected to be set and not to be null');
Utils::assign($object, [], ['requiredKey']);
}

/**
* @param int $input
* @param string $expected
*
* @dataProvider chrUtf8DataProvider
*/
public function testChrUtf8Generation($input, $expected) : void
{
$result = Utils::chr($input);
self::assertTrue(mb_check_encoding($result, 'UTF-8'));
self::assertEquals($expected, $result);
}

public function chrUtf8DataProvider()
{
return [
'alphabet' => [
'input' => 0x0061,
'expected' => 'a',
],
'numeric' => [
'input' => 0x0030,
'expected' => '0',
],
'between 128 and 256' => [
'input' => 0x00E9,
'expected' => 'é',
],
'emoji' => [
'input' => 0x231A,
'expected' => '⌚',
],
];
}
}