Skip to content

Commit 3ec11ff

Browse files
committed
Adding the a test for combined tokens
1 parent b814637 commit 3ec11ff

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/PHPCR/Util/QOM/Sql2Scanner.php

+6
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ protected function scan($sql2)
188188
} elseif (!$stringStartCharacter) {
189189
// If there is no start character already we have found the beginning of a new string
190190
$stringStartCharacter = $character;
191+
192+
// When tokenizing `AS"abc"` add the current token (AS) as token already
193+
if (strlen($currentToken) > 1) {
194+
$tokens[] = substr($currentToken, 0, strlen($currentToken) - 1);
195+
$currentToken = $character;
196+
}
191197
}
192198
}
193199
$isEscaped = $character === '\\';

tests/PHPCR/Tests/Util/QOM/Sql2ScannerTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,41 @@ public function testSQLEscapedStrings2()
124124
$this->expectTokensFromScanner($scanner, $expected);
125125
}
126126

127+
public function testSquareBrakets()
128+
{
129+
$sql = 'WHERE ISSAMENODE(file, ["/home node"])';
130+
131+
$scanner = new Sql2Scanner($sql);
132+
$expected = [
133+
'WHERE',
134+
'ISSAMENODE',
135+
'(',
136+
'file',
137+
',',
138+
'[',
139+
'"/home node"',
140+
']',
141+
')',
142+
];
143+
144+
$this->expectTokensFromScanner($scanner, $expected);
145+
}
146+
147+
public function testTokenizingWithMissingSpaces()
148+
{
149+
$sql = 'SELECT * AS"all"';
150+
151+
$scanner = new Sql2Scanner($sql);
152+
$expected = [
153+
'SELECT',
154+
'*',
155+
'AS',
156+
'"all"',
157+
];
158+
159+
$this->expectTokensFromScanner($scanner, $expected);
160+
}
161+
127162
public function testThrowingErrorOnUnclosedString()
128163
{
129164
$this->expectException(InvalidQueryException::class);

0 commit comments

Comments
 (0)