Skip to content

Commit 7575f33

Browse files
committed
consume trailing CR/LF as part of line-comments
1 parent 66f475e commit 7575f33

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/SQLTokenizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected function token()
121121
protected function comment()
122122
{
123123
if ($start = $this->consume('--')) {
124-
$comment = $this->consume("[^\r\n]*");
124+
$comment = $this->consume(".*?(\n|\r\n|\$)");
125125

126126
return "{$start}{$comment}";
127127
}

test/test.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function () {
4242
test(
4343
'comments',
4444
function () {
45-
eq(SQLTokenizer::tokenize("-- one\nSELECT -- two\n1; -- three\n-- four"), [["-- one", "\n", "SELECT", " ", "-- two", "\n", "1"], ["-- three", "\n", "-- four"]]);
45+
eq(SQLTokenizer::tokenize("-- one\nSELECT -- two\n1; -- three\n-- four"), [["-- one\n", "SELECT", " ", "-- two\n", "1"], ["-- three\n", "-- four"]]);
4646
eq(SQLTokenizer::tokenize("/* one\ntwo */\nSELECT 1;/* three\nfour */\nSELECT 2;"), [["/* one\ntwo */", "\n", "SELECT", " ", "1"], ["/* three\nfour */", "\n", "SELECT", " ", "2"]]);
4747
}
4848
);
@@ -51,7 +51,8 @@ function () {
5151
'split statements',
5252
function () {
5353
eq(SQLSplitter::split("SELECT 1; SELECT 2;"), ["SELECT 1", "SELECT 2"]);
54-
eq(SQLSplitter::split("-- one\nSELECT -- two\n1; -- three\n-- four"), ["SELECT \n1"]);
54+
eq(SQLSplitter::split("-- one\nSELECT -- two\n1; -- three\n-- four"), ["SELECT 1"]);
55+
eq(SQLSplitter::split("-- one\r\nSELECT -- two\r\n1; -- three\r\n-- four\r\n"), ["SELECT 1"]);
5556
eq(SQLSplitter::split("-- one\nSELECT -- two\n1; -- three\n-- four", false), ["-- one\nSELECT -- two\n1", "-- three\n-- four"]);
5657
eq(SQLSplitter::split("/* one\ntwo */\nSELECT 1;/* three\nfour */\nSELECT 2;"), ["SELECT 1", "SELECT 2"]);
5758
eq(SQLSplitter::split("/* one\ntwo */\nSELECT 1;\n/* three\nfour */\nSELECT 2;", false), ["/* one\ntwo */\nSELECT 1", "/* three\nfour */\nSELECT 2"]);

0 commit comments

Comments
 (0)