Skip to content

Commit

Permalink
Fix #18
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Nov 19, 2023
1 parent abb3755 commit 2558b41
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php declare(strict_types = 1);
namespace TheSeer\Tokenizer;

use function var_dump;

class Tokenizer {

/**
Expand Down Expand Up @@ -70,6 +72,18 @@ public function parse(string $source): TokenCollection {
$line = $tok[2];
$values = \preg_split('/\R+/Uu', $tok[1]);

if (!$values) {
$result->addToken(
new Token(
$line,
\token_name($tok[0]),
'{binary data}'
)
);

continue;
}

foreach ($values as $v) {
$token = new Token(
$line,
Expand Down
19 changes: 19 additions & 0 deletions tests/Issue18Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types = 1);
namespace TheSeer\Tokenizer;

use DOMXPath;
use PHPUnit\Framework\TestCase;

class Issue18Test extends TestCase {

public function testIssueNoLongerOccurs() {
$result = (new Tokenizer)->parse(\file_get_contents(__DIR__ . '/_files/Issue-18.php'));

$dom = (new XMLSerializer())->toDom($result);

$node = (new DOMXPath($dom))->query('//*[@no="18"]/*')->item(1);

$this->assertEquals('{binary data}', $node->textContent);
}

}
Binary file added tests/_files/Issue-18.php
Binary file not shown.

0 comments on commit 2558b41

Please sign in to comment.