Skip to content

Commit

Permalink
Merge pull request #26 from nicolas-grekas/utf8
Browse files Browse the repository at this point in the history
Work around PHP bug
  • Loading branch information
alcaeus authored Jun 8, 2019
2 parents ee614dd + f01102e commit 1febd6c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Doctrine/Common/Lexer/AbstractLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ protected function scan($input)
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
$matches = preg_split($regex, $input, -1, $flags);

if (false === $matches) {
// Work around https://bugs.php.net/78122
$matches = array(array($input, 0));
}

foreach ($matches as $match) {
// Must remain before 'value' assignment since it can change content
$type = $this->getType($match[0]);
Expand Down
17 changes: 16 additions & 1 deletion tests/Doctrine/Common/Lexer/AbstractLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function testMoveNext($input, $expectedTokens)
$this->assertNull($this->concreteLexer->lookahead);
}


public function testSkipUntil()
{
$this->concreteLexer->setInput('price=10');
Expand All @@ -141,6 +140,22 @@ public function testSkipUntil()
);
}

public function testUtf8Mismatch()
{
$this->concreteLexer->setInput("\xE9=10");

$this->assertTrue($this->concreteLexer->moveNext());

$this->assertEquals(
array(
'value' => "\xE9=10",
'type' => 'string',
'position' => 0,
),
$this->concreteLexer->lookahead
);
}

/**
* @dataProvider dataProvider
*
Expand Down
5 changes: 5 additions & 0 deletions tests/Doctrine/Common/Lexer/ConcreteLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getType(&$value)

return;
}

protected function getModifiers()
{
return parent::getModifiers().'u';
}
}

0 comments on commit 1febd6c

Please sign in to comment.