Skip to content

Commit

Permalink
Merge branch 'flogado-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Apr 13, 2021
2 parents 7f8420e + fcafc4c commit aba3bd1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.5.2
-----

* Fix SQL 2 scanner delimiter detection to handle that tokens don't necessarily have whitespace between them.

1.5.1
-----

Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Util/QOM/Sql2Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected function scan($sql2)
$regexpTokens[] = preg_quote($token, '/');
}

$regexp = '/^'.implode('([ \t\n]+)', $regexpTokens).'$/';
$regexp = '/^'.implode('([ \t\n]*)', $regexpTokens).'$/';
preg_match($regexp, $sql2, $this->delimiters);
$this->delimiters[0] = '';

Expand Down
47 changes: 47 additions & 0 deletions tests/PHPCR/Tests/Util/QOM/Sql2ScannerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace PHPCR\Tests\Util\QOM;

use PHPCR\Util\QOM\Sql2Scanner;
use PHPUnit\Framework\TestCase;

class Sql2ScannerTest extends TestCase
{
public function testToken()
{
$scanner = new Sql2Scanner('SELECT page.* FROM [nt:unstructured] AS page');
$expected = [
'SELECT',
'page',
'.',
'*',
'FROM',
'[nt:unstructured]',
'AS',
'page',
];

while ($token = $scanner->fetchNextToken()) {
$this->assertEquals(array_shift($expected), $token);
}
}

public function testDelimiter()
{
$scanner = new Sql2Scanner('SELECT page.* FROM [nt:unstructured] AS page');
$expected = [
'',
' ',
'',
'',
' ',
' ',
' ',
' ',
];

while ($token = $scanner->fetchNextToken()) {
$this->assertEquals(array_shift($expected), $scanner->getPreviousDelimiter());
}
}
}

0 comments on commit aba3bd1

Please sign in to comment.