From 8742209c6331befcf0c6df630328bcc7795a5e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 7 Dec 2015 15:33:37 +0100 Subject: [PATCH] Fix single quote export for servers in ANSI_QUOTES mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is possible to escape ' inside '' as both '' and \'. However using '' is MySQL extension and does not work in ANSI mode. We need to generate compatible exports in this case, so sticking with \' is safer. Fixes #11721 Signed-off-by: Michal Čihař --- ChangeLog | 1 + libraries/Util.class.php | 2 +- test/libraries/common/PMA_quoting_slashing_test.php | 12 ++++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90543b65f2..ac57b8bdc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ phpMyAdmin - ChangeLog - issue #11698 Cannot create user on Percona Server - issue Properly report error on connecting - issue #11706 Database export template not saving compression option +- issue #11721 Fix single quote export for servers in ANSI_QUOTES mode 4.5.2.0 (2015-11-23) - issue #11589 Incorrect parameter in mysqli_fetch_fields() diff --git a/libraries/Util.class.php b/libraries/Util.class.php index 701f8c982f..f19ec12600 100644 --- a/libraries/Util.class.php +++ b/libraries/Util.class.php @@ -308,7 +308,7 @@ class PMA_Util if ($php_code) { $a_string = str_replace('\'', '\\\'', $a_string); } else { - $a_string = str_replace('\'', '\'\'', $a_string); + $a_string = str_replace('\'', '\\\'', $a_string); } return $a_string; diff --git a/test/libraries/common/PMA_quoting_slashing_test.php b/test/libraries/common/PMA_quoting_slashing_test.php index 1f29191035..b750aa5dc0 100644 --- a/test/libraries/common/PMA_quoting_slashing_test.php +++ b/test/libraries/common/PMA_quoting_slashing_test.php @@ -35,7 +35,7 @@ class PMA_QuotingSlashing_Test extends PHPUnit_Framework_TestCase PMA_Util::sqlAddSlashes($string, true, true, true) ); $this->assertEquals( - "\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\\r\\t\\n", + "\\\\\\\\\\'test\\'\\'\\\\\\\\\\'\\'\\\\\\\\\\'\\r\\t\\n", PMA_Util::sqlAddSlashes($string, true, true, false) ); $this->assertEquals( @@ -43,7 +43,7 @@ class PMA_QuotingSlashing_Test extends PHPUnit_Framework_TestCase PMA_Util::sqlAddSlashes($string, true, false, true) ); $this->assertEquals( - "\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\r\t\n", + "\\\\\\\\\\'test\\'\\'\\\\\\\\\\'\\'\\\\\\\\\\'\r\t\n", PMA_Util::sqlAddSlashes($string, true, false, false) ); $this->assertEquals( @@ -51,7 +51,7 @@ class PMA_QuotingSlashing_Test extends PHPUnit_Framework_TestCase PMA_Util::sqlAddSlashes($string, false, true, true) ); $this->assertEquals( - "\\\\''test''''\\\\''''\\\\''\\r\\t\\n", + "\\\\\\'test\\'\\'\\\\\\'\\'\\\\\\'\\r\\t\\n", PMA_Util::sqlAddSlashes($string, false, true, false) ); $this->assertEquals( @@ -59,9 +59,13 @@ class PMA_QuotingSlashing_Test extends PHPUnit_Framework_TestCase PMA_Util::sqlAddSlashes($string, false, false, true) ); $this->assertEquals( - "\\\\''test''''\\\\''''\\\\''\r\t\n", + "\\\\\\'test\\'\\'\\\\\\'\\'\\\\\\'\r\t\n", PMA_Util::sqlAddSlashes($string, false, false, false) ); + $this->assertEquals( + "\\\\\\'", + PMA_Util::sqlAddSlashes('\\\'') + ); } /**