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:
commit
96eeddebd0
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,
|
||||||
[
|
'123',
|
||||||
null,
|
"\"c\\a\nb\r",
|
||||||
'123',
|
'123',
|
||||||
"\"c\\a\nb\r",
|
'+30.2103210000',
|
||||||
]
|
],
|
||||||
)
|
[null],
|
||||||
);
|
null
|
||||||
|
|
||||||
$dbi->expects($this->at(7))
|
|
||||||
->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"me2: 123' . "\n" .
|
' fNa"me2: 123' . "\n" .
|
||||||
' fName3: "\"c\\\\a\nb\r"' . "\n" .
|
' fName3: "\"c\\\\a\nb\r"' . "\n" .
|
||||||
|
' fName4: "123"' . "\n" .
|
||||||
|
' fName5: "+30.2103210000"' . "\n" .
|
||||||
'-' . "\n",
|
'-' . "\n",
|
||||||
$result
|
$result
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user