Merge #16715 - When exporting yaml quote strings even when they are numeric

Pull-request: #16715

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-03-05 19:02:32 +01:00
commit 96eeddebd0
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
2 changed files with 44 additions and 35 deletions

View File

@ -16,6 +16,7 @@ use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
use function is_numeric; use function is_numeric;
use function str_replace; use function str_replace;
use function stripslashes; use function stripslashes;
use function strpos;
/** /**
* Handles the export for the YAML format * Handles the export for the YAML format
@ -159,6 +160,8 @@ class ExportYaml extends ExportPlugin
); );
$columns_cnt = $dbi->numFields($result); $columns_cnt = $dbi->numFields($result);
$fieldsMeta = $dbi->getFieldsMeta($result);
$columns = []; $columns = [];
for ($i = 0; $i < $columns_cnt; $i++) { for ($i = 0; $i < $columns_cnt; $i++) {
$col_as = $dbi->fieldName($result, $i); $col_as = $dbi->fieldName($result, $i);
@ -191,7 +194,7 @@ class ExportYaml extends ExportPlugin
continue; continue;
} }
if (is_numeric($record[$i])) { if (is_numeric($record[$i]) && strpos($fieldsMeta[$i]->type, 'string') === false) {
$buffer .= ' ' . $columns[$i] . ': ' . $record[$i] . $crlf; $buffer .= ' ' . $columns[$i] . ': ' . $record[$i] . $crlf;
continue; continue;
} }

View File

@ -13,6 +13,8 @@ use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
use PhpMyAdmin\Tests\AbstractTestCase; use PhpMyAdmin\Tests\AbstractTestCase;
use ReflectionMethod; use ReflectionMethod;
use ReflectionProperty; use ReflectionProperty;
use stdClass;
use function array_shift; use function array_shift;
use function ob_get_clean; use function ob_get_clean;
use function ob_start; use function ob_start;
@ -169,6 +171,28 @@ class ExportYamlTest extends AbstractTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$flags = [];
$a = new stdClass();
$a->type = '';
$flags[] = $a;
$b = new stdClass();
$b->type = '';
$flags[] = $b;
$c = new stdClass();
$c->type = '';
$flags[] = $c;
$d = new stdClass();
$d->type = 'string';
$flags[] = $d;
$e = new stdClass();
$e->type = 'string';
$flags[] = $e;
$dbi->expects($this->once())
->method('getFieldsMeta')
->with(true)
->will($this->returnValue($flags));
$dbi->expects($this->once()) $dbi->expects($this->once())
->method('query') ->method('query')
->with('SELECT', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED) ->with('SELECT', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_UNBUFFERED)
@ -177,44 +201,24 @@ class ExportYamlTest extends AbstractTestCase
$dbi->expects($this->once()) $dbi->expects($this->once())
->method('numFields') ->method('numFields')
->with(true) ->with(true)
->will($this->returnValue(4)); ->will($this->returnValue(5));
$dbi->expects($this->at(2)) $dbi->expects($this->exactly(5))
->method('fieldName') ->method('fieldName')
->will($this->returnValue('fName1')); ->willReturn('fName1', 'fNa"me2', 'fNa\\me3', 'fName4', 'fName5');
$dbi->expects($this->at(3)) $dbi->expects($this->exactly(3))
->method('fieldName')
->will($this->returnValue('fNa"me2'));
$dbi->expects($this->at(4))
->method('fieldName')
->will($this->returnValue('fNa\\me3'));
$dbi->expects($this->at(5))
->method('fieldName')
->will($this->returnValue('fName4'));
$dbi->expects($this->at(6))
->method('fetchRow') ->method('fetchRow')
->with(true) ->willReturn(
->will(
$this->returnValue(
[ [
null, null,
'123', '123',
"\"c\\a\nb\r", "\"c\\a\nb\r",
] '123',
) '+30.2103210000',
); ],
[null],
$dbi->expects($this->at(7)) null
->method('fetchRow')
->with(true)
->will(
$this->returnValue(
[null]
)
); );
$GLOBALS['dbi'] = $dbi; $GLOBALS['dbi'] = $dbi;
@ -236,6 +240,8 @@ class ExportYamlTest extends AbstractTestCase
'-' . "\n" . '-' . "\n" .
' fNa&quot;me2: 123' . "\n" . ' fNa&quot;me2: 123' . "\n" .
' fName3: &quot;\&quot;c\\\\a\nb\r&quot;' . "\n" . ' fName3: &quot;\&quot;c\\\\a\nb\r&quot;' . "\n" .
' fName4: &quot;123&quot;' . "\n" .
' fName5: &quot;+30.2103210000&quot;' . "\n" .
'-' . "\n", '-' . "\n",
$result $result
); );