Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Parsers/OptionsArrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpMyAdmin\SqlParser\Components\OptionsArray;
use PhpMyAdmin\SqlParser\Parseable;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\SqlParser\TokensList;
use PhpMyAdmin\SqlParser\TokenType;
use PhpMyAdmin\SqlParser\Translator;
Expand Down Expand Up @@ -44,7 +45,7 @@
/**
* The index of the option that was processed last time.
*/
$lastOptionId = 0;

Check warning on line 48 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "DecrementInteger": @@ @@ /** * The index of the option that was processed last time. */ - $lastOptionId = 0; + $lastOptionId = -1; /** * Counts brackets.

/**
* Counts brackets.
Expand All @@ -62,9 +63,9 @@
*
* 2 ----------------------[ value ]----------------------> 0
*/
$state = 0;

Check warning on line 66 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "DecrementInteger": @@ @@ * * 2 ----------------------[ value ]----------------------> 0 */ - $state = 0; + $state = -1; for (; $list->idx < $list->count; ++$list->idx) { /**

for (; $list->idx < $list->count; ++$list->idx) {

Check warning on line 68 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThan": @@ @@ */ $state = 0; - for (; $list->idx < $list->count; ++$list->idx) { + for (; $list->idx <= $list->count; ++$list->idx) { /** * Token parsed at this moment. */
/**
* Token parsed at this moment.
*/
Expand All @@ -86,7 +87,24 @@
}

if ($lastOption === null) {
$upper = strtoupper($token->token);
// Backtick-enclosed option names (e.g. `PAGE_COMPRESSED`=1) are
// produced by MariaDB. We accept them only when followed by '='
// so that regular quoted identifiers are not mistaken for options.
if ($token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK) {
$nextIdx = $list->idx + 1;
while ($nextIdx < $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) {

Check warning on line 95 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "While_": @@ @@ // so that regular quoted identifiers are not mistaken for options. if ($token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK) { $nextIdx = $list->idx + 1; - while ($nextIdx < $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) { + while (false) { ++$nextIdx; }

Check warning on line 95 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": @@ @@ // so that regular quoted identifiers are not mistaken for options. if ($token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK) { $nextIdx = $list->idx + 1; - while ($nextIdx < $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) { + while (!($nextIdx < $list->count) && !($list->tokens[$nextIdx]->type === TokenType::Whitespace)) { ++$nextIdx; }

Check warning on line 95 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThanNegotiation": @@ @@ // so that regular quoted identifiers are not mistaken for options. if ($token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK) { $nextIdx = $list->idx + 1; - while ($nextIdx < $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) { + while ($nextIdx >= $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) { ++$nextIdx; }

Check warning on line 95 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThan": @@ @@ // so that regular quoted identifiers are not mistaken for options. if ($token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK) { $nextIdx = $list->idx + 1; - while ($nextIdx < $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) { + while ($nextIdx <= $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) { ++$nextIdx; }
++$nextIdx;

Check warning on line 96 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "Increment": @@ @@ if ($token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK) { $nextIdx = $list->idx + 1; while ($nextIdx < $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) { - ++$nextIdx; + --$nextIdx; } if ($nextIdx >= $list->count || $list->tokens[$nextIdx]->token !== '=') {
}

if ($nextIdx >= $list->count || $list->tokens[$nextIdx]->token !== '=') {

Check warning on line 99 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "GreaterThanOrEqualTo": @@ @@ ++$nextIdx; } - if ($nextIdx >= $list->count || $list->tokens[$nextIdx]->token !== '=') { + if ($nextIdx > $list->count || $list->tokens[$nextIdx]->token !== '=') { break; }
break;
}

$upper = strtoupper((string) $token->value);

Check warning on line 103 in src/Parsers/OptionsArrays.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "UnwrapStrToUpper": @@ @@ break; } - $upper = strtoupper((string) $token->value); + $upper = (string) $token->value; } else { $upper = strtoupper($token->token); }
} else {
$upper = strtoupper($token->token);
}

if (! isset($options[$upper])) {
// There is no option to be processed.
break;
Expand Down
12 changes: 12 additions & 0 deletions tests/Builder/CreateStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public function testBuilderCompressed(): void
);
}

public function testBuilderCompressedBackticks(): void
{
$parser = new Parser(
'CREATE TABLE users ( user_id int ) `PAGE_COMPRESSED`=1 `PAGE_COMPRESSION_LEVEL`=9;',
);
$stmt = $parser->statements[0];
$this->assertEquals(
"CREATE TABLE users (\n `user_id` int\n) PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9",
$stmt->build(),
);
}

public function testBuilderCollate(): void
{
$parser = new Parser(
Expand Down
Loading