Skip to content

Commit

Permalink
Allow to export JSON with unescaped unicode chars
Browse files Browse the repository at this point in the history
This is optional as there are some parsers which have problems with
utf-8, see http://stackoverflow.com/q/4901133/225718

Fixes #12946

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Feb 2, 2017
1 parent 8c102dc commit c0bb952
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -2,6 +2,7 @@ phpMyAdmin - ChangeLog
======================

4.8.0 (not yet released)
- issue #12946 Allow to export JSON with unescaped unicode chars

4.7.0.0 (not yet released)
- patch #12233 [Display] Improve message when renaming database to same name
Expand Down
1 change: 1 addition & 0 deletions export.php
Expand Up @@ -95,6 +95,7 @@
'ods_columns',
'json_structure_or_data',
'json_pretty_print',
'json_unicode',
'xml_structure_or_data',
'xml_export_events',
'xml_export_functions',
Expand Down
7 changes: 7 additions & 0 deletions libraries/config.default.php
Expand Up @@ -1855,6 +1855,13 @@
*/
$cfg['Export']['json_pretty_print'] = false;

/**
* Export functions
*
* @global string $cfg['Export']['json_unicode']
*/
$cfg['Export']['json_unicode'] = true;

/**
*
*
Expand Down
17 changes: 14 additions & 3 deletions libraries/plugins/export/ExportJson.php
Expand Up @@ -43,13 +43,18 @@ public function __construct()
*/
public function encode($data)
{
$options = 0;
if (isset($GLOBALS['json_pretty_print'])
&& $GLOBALS['json_pretty_print']
) {
return json_encode($data, JSON_PRETTY_PRINT);
} else {
return json_encode($data);
$options |= JSON_PRETTY_PRINT;
}
if (isset($GLOBALS['json_unicode'])
&& $GLOBALS['json_unicode']
) {
$options |= JSON_UNESCAPED_UNICODE;
}
return json_encode($data, $options);
}

/**
Expand Down Expand Up @@ -84,6 +89,12 @@ protected function setProperties()
);
$generalOptions->addProperty($leaf);

$leaf = new BoolPropertyItem(
'unicode',
__('Output unicode characters unescaped')
);
$generalOptions->addProperty($leaf);

// add the main group to the root group
$exportSpecificOptions->addProperty($generalOptions);

Expand Down

0 comments on commit c0bb952

Please sign in to comment.