Skip to content

Commit

Permalink
add failing test (#50)
Browse files Browse the repository at this point in the history
* fix parsing for strings ending in \'

* Update InsertQueryTest.php
  • Loading branch information
Scott Sandler committed Aug 18, 2020
1 parent fd16548 commit 046b66f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Parser/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private function groupComments(dict<int, string> $tokens): dict<int, string> {
// we need to handle sequences that look like comments, but are inside quoted strings. to do that, we also need to know when quoted strings start and end
// since a comment could contain a quote, and a quote could contain a comment, we can't safely process either first without being aware of the other
// so first we check if the next token should be escaped, and then if it's a quote character
if ($token === '\\') {
// checking for !$escape_next here checks for \\\\ sequences
if ($token === '\\' && !$escape_next) {
$escape_next = true;
} else {
$escape_next = false;
Expand Down
20 changes: 18 additions & 2 deletions tests/InsertQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ final class InsertQueryTest extends HackTest {
public static async function beforeFirstTestAsync(): Awaitable<void> {
init(TEST_SCHEMA, true);
$pool = new AsyncMysqlConnectionPool(darray[]);
static::$conn = await $pool->connect("example", 1, 'db1', '', '');
// block hole logging
static::$conn = await $pool->connect('example', 1, 'db1', '', '');
// black hole logging
Logger::setHandle(new \Facebook\CLILib\TestLib\StringOutput());
}

Expand Down Expand Up @@ -306,4 +306,20 @@ final class InsertQueryTest extends HackTest {
]);
}

public async function testDupeInsertEscaping(): Awaitable<void> {
$conn = static::$conn as nonnull;
await $conn->query(<<<'EOT'
INSERT INTO table1 (`id`,`name`) VALUES (123456789, 'xÚdfíá()ÊÏMÊÏKòáÂÕÿfl©99ùåp>sQj¤Ø©¸¨©=)7±(I{^PSj\\%Krbv*+#©¶ Ì\0Ma\0a\0¤Ý7\\')
ON DUPLICATE KEY UPDATE `name`='xÚdfíá()ÊÏMÊÏKòáÂÕÿfl©99ùåp>sQj¤Ø©¸¨©=)7±(I{^PSj\\%Krbv*+#©¶ Ì\0Ma\0a\0¤Ý7\\'
EOT
);
$results = await $conn->query("SELECT * FROM table1");
expect($results->rows())->toBeSame(vec[
dict[
'id' => 123456789,
'name' =>
"xÚdfíá()ÊÏMÊÏKòáÂÕÿfl©99ùåp>sQj¤Ø©¸¨©=)7±(I{^PSj\%Krbv*+#©¶ Ì\0Ma\0a\0¤Ý7\\",
],
]);
}
}

0 comments on commit 046b66f

Please sign in to comment.