Skip to content

Commit

Permalink
Remove options for JSON view.
Browse files Browse the repository at this point in the history
json_encode() does not support options in 5.2. Because 2.6.x is 5.2
compatible we have to remove these options. People needing these options
should upgrade to 2.7.x

Refs #7083
  • Loading branch information
markstory committed Aug 6, 2015
1 parent 727b73e commit d82f276
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
25 changes: 0 additions & 25 deletions lib/Cake/Test/Case/View/JsonViewTest.php
Expand Up @@ -194,31 +194,6 @@ public function testRenderWithoutView($data, $serialize, $expected) {
$this->assertSame($expected, $output);
}

/**
* Test render with _jsonOptions setting.
*
* @return void
*/
public function testRenderWithoutViewJsonOptions() {
$this->skipIf(!version_compare(PHP_VERSION, '5.3.0', '>='), 'Needs PHP5.3+ for these constants to be tested');

$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);

// Test render with encode <, >, ', &, and " for RFC4627-compliant to be serialized.
$data = array('rfc4627_escape' => '<tag> \'quote\' "double-quote" &');
$serialize = 'rfc4627_escape';
$expected = json_encode('<tag> \'quote\' "double-quote" &', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);

$Controller->set($data);
$Controller->set('_serialize', $serialize);
$Controller->set('_jsonOptions', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
$View = new JsonView($Controller);
$output = $View->render(false);

$this->assertSame($expected, $output);
}
/**
* Test that rendering with _serialize does not load helpers.
*
Expand Down
14 changes: 1 addition & 13 deletions lib/Cake/View/JsonView.php
Expand Up @@ -149,19 +149,7 @@ protected function _serialize($serialize) {
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
}

$jsonOptions = 0;
if (isset($this->viewVars['_jsonOptions'])) {
if ($this->viewVars['_jsonOptions'] === false) {
$jsonOptions = 0;
} else {
$jsonOptions = $this->viewVars['_jsonOptions'];
}
}
if (version_compare(PHP_VERSION, '5.4.0', '>=') && Configure::read('debug')) {
$jsonOptions = $jsonOptions | JSON_PRETTY_PRINT;
}

$json = json_encode($data, $jsonOptions);
$json = json_encode($data);

if (function_exists('json_last_error') && json_last_error() !== JSON_ERROR_NONE) {
throw new CakeException(json_last_error_msg());
Expand Down

0 comments on commit d82f276

Please sign in to comment.