From d94e05cf7683bd89067b9b440592108b98e1ff78 Mon Sep 17 00:00:00 2001 From: Rob McVey Date: Sun, 15 Mar 2015 11:01:51 +0000 Subject: [PATCH] Assert exception msg contains UTF-8 The different versions of PHP throw several various messages for UTF-8 sequences, so this just performs a basic regex check --- lib/Cake/Test/Case/View/JsonViewTest.php | 6 +----- lib/Cake/View/JsonView.php | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/View/JsonViewTest.php b/lib/Cake/Test/Case/View/JsonViewTest.php index 8317ac5b5..f3a5902d5 100644 --- a/lib/Cake/Test/Case/View/JsonViewTest.php +++ b/lib/Cake/Test/Case/View/JsonViewTest.php @@ -351,12 +351,8 @@ class JsonViewTest extends CakeTestCase { restore_error_handler(); $this->fail('Failed asserting that exception of type "CakeException" is thrown.'); } catch (CakeException $e) { - $expected = array( - 'Failed to parse JSON', - 'Malformed UTF-8 characters, possibly incorrectly encoded' - ); - $this->assertContains($e->getMessage(), $expected); restore_error_handler(); + $this->assertRegExp('/UTF-8/', $e->getMessage()); return; } diff --git a/lib/Cake/View/JsonView.php b/lib/Cake/View/JsonView.php index fb25a34a1..7953803de 100644 --- a/lib/Cake/View/JsonView.php +++ b/lib/Cake/View/JsonView.php @@ -152,7 +152,7 @@ class JsonView extends View { } if (function_exists('json_last_error') && json_last_error() !== JSON_ERROR_NONE) { - throw new CakeException(sprintf('JSON_ERROR: %s', json_last_error_msg())); + throw new CakeException(json_last_error_msg()); } elseif ($json === false) { throw new CakeException('Failed to parse JSON'); }