From f63a765279297bf142a301024aa393c0572f3aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 4 Jun 2004 10:20:33 +0000 Subject: [PATCH] Handle correctly all MySQL comments (-- can be followed with any control char) (patch #965106). --- ChangeLog | 5 +++++ libraries/read_dump.lib.php | 25 ------------------------- libraries/sqlparser.lib.php | 10 ++-------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6bdd6d3fa..e2b58163e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - Changelog $Id$ $Source$ +2004-06-04 Michal Čihař + * libraries/read_dump.lib.php: Do not strip comments here. + * libraries/sqlparser.lib.php: Handle correctly all MySQL comments (-- can + be followed with any control char) (patch #965106). + 2004-06-04 Garvin Hicking * Bug #959320: Broken row highlighting in vertical browsing mode fixed. The pointer will now highlight diff --git a/libraries/read_dump.lib.php b/libraries/read_dump.lib.php index 4895502b5..6c6b8994b 100644 --- a/libraries/read_dump.lib.php +++ b/libraries/read_dump.lib.php @@ -90,31 +90,6 @@ function PMA_splitSqlFile(&$ret, $sql, $release) $string_start = $char; } // end else if (is start of string) - // ... for start of a comment (and remove this comment if found)... - else if ($char == '#' - || ($char == ' ' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '--')) { - // starting position of the comment depends on the comment type - $start_of_comment = (($sql[$i] == '#') ? $i : $i-2); - // if no "\n" exits in the remaining string, checks for "\r" - // (Mac eol style) - $end_of_comment = (strpos(' ' . $sql, "\012", $i+2)) - ? strpos(' ' . $sql, "\012", $i+2) - : strpos(' ' . $sql, "\015", $i+2); - if (!$end_of_comment) { - // no eol found after '#', add the parsed part to the returned - // array if required and exit - if ($start_of_comment > 0) { - $ret[] = trim(substr($sql, 0, $start_of_comment)); - } - return TRUE; - } else { - $sql = substr($sql, 0, $start_of_comment) - . ltrim(substr($sql, $end_of_comment)); - $sql_len = strlen($sql); - $i--; - } // end if...else - } // end else if (is comment) - // ... and finally disactivate the "/*!...*/" syntax if MySQL < 3.22.07 else if ($release < 32270 && ($char == '!' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '/*')) { diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 927774054..9dfde489d 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -268,7 +268,7 @@ if ($is_minimum_common == FALSE) { if (($c == '#') || (($count2 + 1 < $len) && ($c == '/') && (PMA_substr($sql, $count2 + 1, 1) == '*')) || (($count2 + 2 == $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-')) - || (($count2 + 2 < $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-') && ((PMA_substr($sql, $count2 + 2, 1) == ' ') || (PMA_substr($sql, $count2 + 2, 1) == "\n")))) { + || (($count2 + 2 < $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-') && ((PMA_substr($sql, $count2 + 2, 1) <= ' ')))) { $count2++; $pos = 0; $type = 'bad'; @@ -422,13 +422,7 @@ if ($is_minimum_common == FALSE) { if (($first == ',') || ($first == ';') || ($first == '.') || ($first == '*')) { $count2 = $count1 + 1; $punct_data = $first; - } else if (($last2 == '--') && $l == 2) { - // Nijel: probably broken ANSI comment here (bug #905066) - $debugstr = $GLOBALS['strSQPBugSyntaxError'] . ' @ ' . ($count1+1) . "\n" - . 'STR: ' . $punct_data; - PMA_SQP_throwError($debugstr, $sql); - return $sql; - } else if (($last2 == '/*') || ($last2 == '--')) { + } else if (($last2 == '/*') || (($last2 == '--') && ($count2 == $len || PMA_substr($sql, $count2, 1) <= ' ') )) { $count2 -= 2; $punct_data = PMA_substr($sql, $count1, $count2 - $count1); } else if (($last == '-') || ($last == '+') || ($last == '!')) {