From c1b00661d450e172160445201fcc0e5097c7d55a Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 21 Jan 2013 13:07:25 +0000 Subject: [PATCH 1/3] Dropped custom enum/set parser. Fixes bug #3779 --- ChangeLog | 1 + libraries/common.lib.php | 60 ++++++---------------------------------- tbl_change.php | 2 -- 3 files changed, 9 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index c0367cfd1c..9bf52bbc9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ phpMyAdmin - ChangeLog ====================== 3.5.7.0 (not yet released) +- bug #3779 [core] Problem with backslash in enum fields 3.5.6.0 (not yet released) - bug #3593604 [status] Erroneous advisor rule diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 73beaf6e24..376b6a7e95 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -2927,57 +2927,7 @@ function PMA_extractFieldSpec($fieldspec) if ('enum' == $type || 'set' == $type) { // Define our working vars - $enum_set_values = array(); - $working = ""; - $in_string = false; - $index = 0; - - // While there is another character to process - while (isset($fieldspec[$index])) { - // Grab the char to look at - $char = $fieldspec[$index]; - - // If it is a single quote, needs to be handled specially - if ($char == "'") { - // If we are not currently in a string, begin one - if (! $in_string) { - $in_string = true; - $working = ""; - } else { - // Otherwise, it may be either an end of a string, - // or a 'double quote' which can be handled as-is - // Check out the next character (if possible) - $has_next = isset($fieldspec[$index + 1]); - $next = $has_next ? $fieldspec[$index + 1] : null; - - //If we have reached the end of our 'working' string (because - //there are no more chars,or the next char is not another quote) - if (! $has_next || $next != "'") { - $enum_set_values[] = $working; - $in_string = false; - - } elseif ($next == "'") { - // Otherwise, this is a 'double quote', - // and can be added to the working string - $working .= "'"; - // Skip the next char; we already know what it is - $index++; - } - } - } elseif ('\\' == $char - && isset($fieldspec[$index + 1]) - && "'" == $fieldspec[$index + 1] - ) { - // escaping of a quote? - $working .= "'"; - $index++; - } else { - // Otherwise, add it to our working string like normal - $working .= $char; - } - // Increment character index - $index++; - } // end while + $enum_set_values = PMA_parseEnumSetValues($fieldspec, false); $printtype = $type . '(' . str_replace("','", "', '", $spec_in_brackets) . ')'; $binary = false; $unsigned = false; @@ -3843,10 +3793,11 @@ function PMA_printButton() * * @param string $definition The definition of the column * for which to parse the values + * @param bool $escapeHtml Whether to escape html entitites * * @return array */ -function PMA_parseEnumSetValues($definition) +function PMA_parseEnumSetValues($definition, $escapeHtml = true) { $values_string = htmlentities($definition); // There is a JS port of the below parser in functions.js @@ -3878,6 +3829,11 @@ function PMA_parseEnumSetValues($definition) // The leftovers in the buffer are the last value (if any) $values[] = $buffer; } + if (! $escapeHtml) { + foreach ($values as $key => $value) { + $values[$key] = html_entity_decode($value, ENT_QUOTES); + } + } return $values; } diff --git a/tbl_change.php b/tbl_change.php index 2cffd16ebd..6ec71c66ab 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -702,8 +702,6 @@ foreach ($rows as $row_id => $vrow) { if (! isset($table_fields[$i]['values'])) { $table_fields[$i]['values'] = array(); foreach ($extracted_fieldspec['enum_set_values'] as $val) { - // Removes automatic MySQL escape format - $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val)); $table_fields[$i]['values'][] = array( 'plain' => $val, 'html' => htmlspecialchars($val), From fe9a550ff0b93f5cbbc26d39a9a9523e7053bb6f Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 21 Jan 2013 13:08:00 +0000 Subject: [PATCH 2/3] Added extra unit test for enum fields parsing --- test/libraries/common/PMA_extractFieldSpec_test.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/libraries/common/PMA_extractFieldSpec_test.php b/test/libraries/common/PMA_extractFieldSpec_test.php index cb5bb1e8ff..6c35857fb2 100644 --- a/test/libraries/common/PMA_extractFieldSpec_test.php +++ b/test/libraries/common/PMA_extractFieldSpec_test.php @@ -74,6 +74,19 @@ class PMA_extractFieldSpec_test extends PHPUnit_Framework_TestCase 'attribute' => ' ', ), ), + array( + "ENUM('a&b', 'b''c\\'d', 'e\\\\f')", + array( + 'type' => 'enum', + 'print_type' => "enum('a&b', 'b''c\\'d', 'e\\\\f')", + 'binary' => false, + 'unsigned' => false, + 'zerofill' => false, + 'spec_in_brackets' => "'a&b', 'b''c\\'d', 'e\\\\f'", + 'enum_set_values' => array('a&b', 'b\'c\'d', 'e\\f'), + 'attribute' => ' ', + ), + ), array( "INT UNSIGNED zerofill", array( From bf278f3d8d4d5119616a67a5d9aae30c088915e9 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Mon, 21 Jan 2013 13:09:07 +0000 Subject: [PATCH 3/3] Coding style fixes --- .../common/PMA_extractFieldSpec_test.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/libraries/common/PMA_extractFieldSpec_test.php b/test/libraries/common/PMA_extractFieldSpec_test.php index 6c35857fb2..dcf48d9418 100644 --- a/test/libraries/common/PMA_extractFieldSpec_test.php +++ b/test/libraries/common/PMA_extractFieldSpec_test.php @@ -46,8 +46,8 @@ class PMA_extractFieldSpec_test extends PHPUnit_Framework_TestCase 'spec_in_brackets' => "'a','b'", 'enum_set_values' => array('a', 'b'), 'attribute' => ' ', - ), ), + ), array( "SET('\'a','b')", array( @@ -59,8 +59,8 @@ class PMA_extractFieldSpec_test extends PHPUnit_Framework_TestCase 'spec_in_brackets' => "'\'a','b'", 'enum_set_values' => array("'a", 'b'), 'attribute' => ' ', - ), ), + ), array( "SET('''a','b')", array( @@ -72,8 +72,8 @@ class PMA_extractFieldSpec_test extends PHPUnit_Framework_TestCase 'spec_in_brackets' => "'''a','b'", 'enum_set_values' => array("'a", 'b'), 'attribute' => ' ', - ), ), + ), array( "ENUM('a&b', 'b''c\\'d', 'e\\\\f')", array( @@ -85,8 +85,8 @@ class PMA_extractFieldSpec_test extends PHPUnit_Framework_TestCase 'spec_in_brackets' => "'a&b', 'b''c\\'d', 'e\\\\f'", 'enum_set_values' => array('a&b', 'b\'c\'d', 'e\\f'), 'attribute' => ' ', - ), ), + ), array( "INT UNSIGNED zerofill", array( @@ -98,8 +98,8 @@ class PMA_extractFieldSpec_test extends PHPUnit_Framework_TestCase 'spec_in_brackets' => '', 'enum_set_values' => array(), 'attribute' => 'UNSIGNED ZEROFILL', - ), ), + ), array( "VARCHAR(255)", array( @@ -111,8 +111,8 @@ class PMA_extractFieldSpec_test extends PHPUnit_Framework_TestCase 'spec_in_brackets' => '255', 'enum_set_values' => array(), 'attribute' => ' ', - ), ), + ), array( "VARBINARY(255)", array( @@ -124,8 +124,8 @@ class PMA_extractFieldSpec_test extends PHPUnit_Framework_TestCase 'spec_in_brackets' => '255', 'enum_set_values' => array(), 'attribute' => ' ', - ), ), - ); + ), + ); } }