From d519c9039e786b731925181eb74e606173fcec78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 20 Sep 2016 09:11:03 +0200 Subject: [PATCH] Update SQL parser to 3.4.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - issue #12298 Fixed export of view definitions Signed-off-by: Michal Čihař --- ChangeLog | 1 + .../src/Components/OptionsArray.php | 14 +++++--- .../src/Statements/CreateStatement.php | 3 +- .../src/Statements/InsertStatement.php | 2 -- libraries/sql-parser/src/Utils/Formatter.php | 36 ++++++++++++++++--- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index d7f7381233..a6cba5f334 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,7 @@ phpMyAdmin - ChangeLog - issue #12554 Absence of scrolling makes it impossible to read longer text values in grid editing - issue #12530 "Edit routine" crashes when the current user is not the definer, even if privileges are adequate - issue #12300 Export selective tables by-default dumps Events also +- issue #12298 Fixed export of view definitions 4.6.4 (2016-08-16) - issue [security] Weaknesses with cookie encryption, see PMASA-2016-29 diff --git a/libraries/sql-parser/src/Components/OptionsArray.php b/libraries/sql-parser/src/Components/OptionsArray.php index c048e19b29..684e5cc12d 100644 --- a/libraries/sql-parser/src/Components/OptionsArray.php +++ b/libraries/sql-parser/src/Components/OptionsArray.php @@ -183,7 +183,7 @@ class OptionsArray extends Component 'value' => '', ); $state = 1; - } elseif ($lastOption[1] === 'expr') { + } elseif ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') { // This is a keyword that is followed by an expression. // The expression is used by the specialized parser. @@ -192,8 +192,11 @@ class OptionsArray extends Component $ret->options[$lastOptionId] = array( // @var string The name of the option. 'name' => $token->value, + // @var bool Whether it contains an equal sign. + // This is used by the builder to rebuild it. + 'equals' => $lastOption[1] === 'expr=', // @var Expression The parsed expression. - 'expr' => null, + 'expr' => '', ); $state = 1; } @@ -208,7 +211,7 @@ class OptionsArray extends Component // This is outside the `elseif` group above because the change might // change this iteration. if ($state === 2) { - if ($lastOption[1] === 'expr') { + if ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') { $ret->options[$lastOptionId]['expr'] = Expression::parse( $parser, $list, @@ -250,7 +253,8 @@ class OptionsArray extends Component && $lastOption && ($lastOption[1] == 'expr' || $lastOption[1] == 'var' - || $lastOption[1] == 'var=') + || $lastOption[1] == 'var=' + || $lastOption[1] == 'expr=') ) { $parser->error( sprintf( @@ -287,7 +291,7 @@ class OptionsArray extends Component $options[] = $option; } else { $options[] = $option['name'] - . (!empty($option['equals']) ? '=' : ' ') + . ((!empty($option['equals']) && $option['equals']) ? '=' : ' ') . (!empty($option['expr']) ? $option['expr'] : $option['value']); } } diff --git a/libraries/sql-parser/src/Statements/CreateStatement.php b/libraries/sql-parser/src/Statements/CreateStatement.php index 47340b572f..1c768cbbf1 100644 --- a/libraries/sql-parser/src/Statements/CreateStatement.php +++ b/libraries/sql-parser/src/Statements/CreateStatement.php @@ -11,7 +11,6 @@ namespace SqlParser\Statements; use SqlParser\Parser; use SqlParser\Statement; use SqlParser\Token; -use SqlParser\Context; use SqlParser\TokensList; use SqlParser\Components\ArrayObj; use SqlParser\Components\DataType; @@ -48,7 +47,7 @@ class CreateStatement extends Statement 'OR REPLACE' => array(2, 'var='), 'ALGORITHM' => array(3, 'var='), // `DEFINER` is also used for `CREATE FUNCTION / PROCEDURE` - 'DEFINER' => array(4, 'var='), + 'DEFINER' => array(4, 'expr='), 'SQL SECURITY' => array(5, 'var'), 'DATABASE' => 6, diff --git a/libraries/sql-parser/src/Statements/InsertStatement.php b/libraries/sql-parser/src/Statements/InsertStatement.php index e684c4e203..164b52c967 100644 --- a/libraries/sql-parser/src/Statements/InsertStatement.php +++ b/libraries/sql-parser/src/Statements/InsertStatement.php @@ -153,8 +153,6 @@ class InsertStatement extends Statement ); ++$list->idx; - $token = $list->tokens[$list->idx]; - /** * The state of the parser. * diff --git a/libraries/sql-parser/src/Utils/Formatter.php b/libraries/sql-parser/src/Utils/Formatter.php index 56691ebbfb..41b50945b5 100644 --- a/libraries/sql-parser/src/Utils/Formatter.php +++ b/libraries/sql-parser/src/Utils/Formatter.php @@ -73,7 +73,7 @@ class Formatter * * @var string */ - 'line_ending' => $this->options['type'] == 'html' ? '
' : "\n", + 'line_ending' => NULL, /** * The string used for indentation. @@ -172,6 +172,10 @@ class Formatter $options ); + if (is_null($this->options['line_ending'])) { + $this->options['line_ending'] = $this->options['type'] == 'html' ? '
' : "\n"; + } + // `parts_newline` requires `clause_newline` $this->options['parts_newline'] &= $this->options['clause_newline']; } @@ -426,6 +430,27 @@ class Formatter return $ret; } + public function escapeConsole($string) + { + return str_replace( + array( + "\x00", "\x01", "\x02", "\x03", "\x04", + "\x05", "\x06", "\x07", "\x08", "\x09", "\x0A", + "\x0B","\x0C","\x0D", "\x0E", "\x0F", "\x10", "\x11", + "\x12","\x13","\x14","\x15", "\x16", "\x17", "\x18", + "\x19","\x1A","\x1B","\x1C","\x1D", "\x1E", "\x1F" + ), + array( + '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', + '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', + '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', + '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F' + ), + $string + ); + } + /** * Tries to print the query and returns the result. * @@ -449,9 +474,9 @@ class Formatter // Formatting HTML. if ($this->options['type'] === 'html') { - return '' . $text . ''; + return '' . htmlspecialchars($text, ENT_NOQUOTES) . ''; } elseif ($this->options['type'] === 'cli') { - return $format['cli'] . $text; + return $format['cli'] . $this->escapeConsole($text); } break; @@ -459,9 +484,10 @@ class Formatter } if ($this->options['type'] === 'cli') { - return "\x1b[39m" . $text; + return "\x1b[39m" . $this->escapeConsole($text); + } elseif ($this->options['type'] === 'html') { + return htmlspecialchars($text, ENT_NOQUOTES); } - return $text; } /**