From 07c4a73eb0734b704339666c70d22b572424bf13 Mon Sep 17 00:00:00 2001 From: Corey Buckley Date: Fri, 24 Jan 2020 16:56:37 -0500 Subject: [PATCH 1/2] Changes trim to regex in convertBitDefaultValue Fixes the issue described in #15831. Signed-off-by: Corey Buckley --- libraries/classes/Util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 7b97adbb7b..bc1436e64d 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -2858,7 +2858,7 @@ class Util */ public static function convertBitDefaultValue($bit_default_value) { - return rtrim(ltrim(htmlspecialchars_decode($bit_default_value, ENT_QUOTES), "b'"), "'"); + return preg_replace("/^b'(.*?)'?$/s", '$1', htmlspecialchars_decode($bit_default_value, ENT_QUOTES), 1); } /** From fcb451d70bdc319bf72ef11a9d3e17c30fbf9bdd Mon Sep 17 00:00:00 2001 From: corey buckley Date: Sat, 25 Jan 2020 13:49:26 -0500 Subject: [PATCH 2/2] Tests added for convertBitDefaultValue. Consider valid database names with single quotes. Change regex to only replace if digits between b'..' Signed-off-by: Corey Buckley --- libraries/classes/Util.php | 2 +- test/classes/UtilTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index bc1436e64d..7cdc9d45de 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -2858,7 +2858,7 @@ class Util */ public static function convertBitDefaultValue($bit_default_value) { - return preg_replace("/^b'(.*?)'?$/s", '$1', htmlspecialchars_decode($bit_default_value, ENT_QUOTES), 1); + return preg_replace("/^b'(\d*)'?$/", '$1', htmlspecialchars_decode($bit_default_value, ENT_QUOTES), 1); } /** diff --git a/test/classes/UtilTest.php b/test/classes/UtilTest.php index 9a59e97d8f..1cbc942a86 100644 --- a/test/classes/UtilTest.php +++ b/test/classes/UtilTest.php @@ -483,6 +483,22 @@ class UtilTest extends PmaTestCase "b'010111010'", "010111010", ], + "database name starting with b" => [ + "big database", + "big database", + ], + "database name containing b'" => [ + "a b'ig database", + "a b'ig database", + ], + "database name in single quotes" => [ + "'a*database*name'", + "'a*database*name'", + ], + "database name with multiple b'" => [ + "b'ens datab'ase'", + "b'ens datab'ase'", + ], ]; }