diff --git a/ChangeLog b/ChangeLog index 58dd4f1e60..c685462bea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,7 +30,7 @@ phpMyAdmin - ChangeLog - bug #4439 Table list in left panel doesn't expand + rfe Improved validation when inserting data + rfe #1491 Support InnoDB for database Query by example -+ rfe #345 Normalize a table ++ rfe #345 Normalize a table + rfe #1123 Zeroconf PMA tables support + rfe #1492 Remove the distinct query window / Add SQL log+history panel + rfe #919 Multiple-column foreign key relation @@ -41,6 +41,7 @@ phpMyAdmin - ChangeLog + MariaDB 10+ multi-master replication support + rfe #1544 MySQL 5.7.5 compatibility + rfe #1529 Avoid session timeout when user is active +- bug #4528 Can't import dump via SQL field 4.2.9.0 (not yet released) - bug ajax.js responseHandler: cannot read property of null diff --git a/libraries/String.class.php b/libraries/String.class.php index 94aaf19607..730ba5ab25 100644 --- a/libraries/String.class.php +++ b/libraries/String.class.php @@ -270,6 +270,22 @@ class PMA_String implements PMA_StringByte, PMA_StringType return $this->_byte->strtoupper($string); } + /** + * Returns position of $needle in $haystack from a regular expression match + * + * @param string $pattern Pattern to search for + * @param string $subject Input string + * @param int $offset Start from search + * + * @return integer position of $needle in $haystack or false + * + * @todo add unit tests + */ + public function pregStrpos($pattern, $subject, $offset = 0) + { + return $this->_byte->pregStrpos($pattern, $subject, $offset); + } + /** * Get the ordinal value of a string * diff --git a/libraries/StringByte.int.php b/libraries/StringByte.int.php index 1da970a921..d130ec6f95 100644 --- a/libraries/StringByte.int.php +++ b/libraries/StringByte.int.php @@ -141,6 +141,17 @@ interface PMA_StringByte */ public function strtoupper($string); + /** + * Returns position of $needle in $haystack from a regular expression match + * + * @param string $pattern Pattern to search for + * @param string $subject Input string + * @param int $offset Start from search + * + * @return integer position of $needle in $haystack or false + */ + public function pregStrpos($pattern, $subject, $offset = 0); + /** * Get the ordinal value of a string * diff --git a/libraries/StringMB.class.php b/libraries/StringMB.class.php index aa1bb98978..74ef6c7774 100644 --- a/libraries/StringMB.class.php +++ b/libraries/StringMB.class.php @@ -293,5 +293,28 @@ class PMA_StringMB implements PMA_StringByte 'UCS-4BE' ); } + + /** + * Perform a regular expression match + * + * @param string $pattern Pattern to search for + * @param string $subject Input string + * @param int $offset Start from search + * + * @return int 1 if matched, 0 if doesn't, false on failure + */ + public function pregStrpos($pattern, $subject, $offset = 0) + { + $matches = array(); + $bFind = preg_match( + $pattern, $subject, $matches, PREG_OFFSET_CAPTURE, $offset + ); + if (1 !== $bFind) { + return false; + } + + $strFound = $matches[1][0]; + return $this->strpos($subject, $strFound, $offset); + } } ?> diff --git a/libraries/StringNative.class.php b/libraries/StringNative.class.php index 5cfa4ae86a..a70f1bcc4d 100644 --- a/libraries/StringNative.class.php +++ b/libraries/StringNative.class.php @@ -197,6 +197,28 @@ class PMA_StringNative implements PMA_StringByte return strtoupper($string); } + /** + * Perform a regular expression match + * + * @param string $pattern Pattern to search for + * @param string $subject Input string + * @param int $offset Start from search + * + * @return int 1 if matched, 0 if doesn't, false on failure + */ + public function pregStrpos($pattern, $subject, $offset = 0) + { + $matches = array(); + $bFind = preg_match( + $pattern, $subject, $matches, PREG_OFFSET_CAPTURE, $offset + ); + if (1 !== $bFind) { + return false; + } + + return $matches[1][1]; + } + /** * Get the ordinal value of a string * diff --git a/libraries/plugins/import/ImportSql.class.php b/libraries/plugins/import/ImportSql.class.php index 351cb9f9f6..98dc3ee93b 100644 --- a/libraries/plugins/import/ImportSql.class.php +++ b/libraries/plugins/import/ImportSql.class.php @@ -194,18 +194,16 @@ class ImportSql extends ImportPlugin $old_i = $i; // this is about 7 times faster that looking for each sequence i // one by one with strpos() - $match = preg_match( + $posPattern = $pmaString->pregStrpos( '/(\'|"|#|-- |\/\*|`|(?i)(?substr($buffer, $i, 1); // Quotes if ($pmaString->strpos('\'"`', $ch) !== false) { @@ -279,7 +278,7 @@ class ImportSql extends ImportPlugin } // Was not the quote escaped? $j = $pos - 1; - while ($buffer[$j] == '\\') { + while ($pmaString->substr($buffer, $j, 1) == '\\') { $j--; } // Even count means it was not escaped @@ -305,8 +304,10 @@ class ImportSql extends ImportPlugin // Not enough data to decide if ((($i == ($len - 1) && ($ch == '-' || $ch == '/')) - || ($i == ($len - 2) && (($ch == '-' && $buffer[$i + 1] == '-') - || ($ch == '/' && $buffer[$i + 1] == '*')))) + || ($i == ($len - 2) && (($ch == '-' + && $pmaString->substr($buffer, $i + 1, 1) == '-') + || ($ch == '/' + && $pmaString->substr($buffer, $i + 1, 1) == '*')))) && ! $GLOBALS['finished'] ) { break; @@ -314,10 +315,13 @@ class ImportSql extends ImportPlugin // Comments if ($ch == '#' - || ($i < ($len - 1) && $ch == '-' && $buffer[$i + 1] == '-' - && (($i < ($len - 2) && $buffer[$i + 2] <= ' ') - || ($i == ($len - 1) && $GLOBALS['finished']))) - || ($i < ($len - 1) && $ch == '/' && $buffer[$i + 1] == '*') + || ($i < ($len - 1) && $ch == '-' + && $pmaString->substr($buffer, $i + 1, 1) == '-' + && (($i < ($len - 2) + && $pmaString->substr($buffer, $i + 2, 1) <= ' ') + || ($i == ($len - 1) && $GLOBALS['finished']))) + || ($i < ($len - 1) && $ch == '/' + && $pmaString->substr($buffer, $i + 1, 1) == '*') ) { // Copy current string to SQL if ($start_pos != $i) {