From 5559e3f2b9b1922f1fe24d4efa0dbc86d38d5232 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 14 Jan 2009 21:22:00 +0000 Subject: [PATCH] API: Clean up invalid UTF-8 in the result before feeding it to the formatter. This should fix bug 15261 (trimmed multibyte chars) and bug 16262 (chars like \x0f) --- RELEASE-NOTES | 1 + includes/api/ApiMain.php | 1 + includes/api/ApiResult.php | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 06621c710a..4feeb46d57 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -50,6 +50,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions and listing all deleted pages possible * (bug 16844) Added clcategories parameter to prop=categories +* (bug 15261, 16262) API no longer outputs invalid UTF-8 === Languages updated in 1.15 === diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index e94f173162..ce4547a3d6 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -438,6 +438,7 @@ class ApiMain extends ApiBase { * Print results using the current printer */ protected function printResult($isError) { + $this->getResult()->cleanupUTF8(); $printer = $this->mPrinter; $printer->profileIn(); diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index a3a1209b10..307101574b 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -186,6 +186,15 @@ class ApiResult extends ApiBase { ApiResult :: setElement($data, $name, $value); // Add named element } + /** + * Ensure all values in this result are valid UTF-8. + */ + public function cleanUpUTF8() + { + $data = & $this->getData(); + array_walk_recursive($data, array('UtfNormal', 'cleanUp')); + } + public function execute() { ApiBase :: dieDebug(__METHOD__, 'execute() is not supported on Result object'); } -- 2.20.1