From 5f48b3e5d202635b5bfb6d77f63d706d57c46118 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Mon, 13 Aug 2018 12:16:42 +0100 Subject: [PATCH] FIX txt/json is not a valid content type --- admin/code/LeftAndMain.php | 2 +- admin/javascript/LeftAndMain.js | 2 +- admin/tests/LeftAndMainTest.php | 8 ++++---- control/PjaxResponseNegotiator.php | 2 +- tests/control/PjaxResponseNegotiatorTest.php | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index fb9a49043..13e16852e 100644 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -1032,7 +1032,7 @@ class LeftAndMain extends Controller implements PermissionProvider { 'PrevID' => $prev ? $prev->ID : null ); } - $this->getResponse()->addHeader('Content-Type', 'text/json'); + $this->getResponse()->addHeader('Content-Type', 'application/json'); return Convert::raw2json($data); } diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 20d847a95..c2b3a2620 100644 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -748,7 +748,7 @@ jQuery.noConflict(); if(title) document.title = decodeURIComponent(title.replace(/\+/g, ' ')); var newFragments = {}, newContentEls; - // If content type is text/json (ignoring charset and other parameters) + // If content type is application/json (ignoring charset and other parameters) if(xhr.getResponseHeader('Content-Type').match(/^((text)|(application))\/json[ \t]*;?/i)) { newFragments = data; } else { diff --git a/admin/tests/LeftAndMainTest.php b/admin/tests/LeftAndMainTest.php index 63bfbc8a9..f040bdaf5 100644 --- a/admin/tests/LeftAndMainTest.php +++ b/admin/tests/LeftAndMainTest.php @@ -243,7 +243,7 @@ class LeftAndMainTest extends FunctionalTest { // Check page $result = $this->get('LeftAndMainTest_Controller/updatetreenodes?ids='.$page1->ID); $this->assertEquals(200, $result->getStatusCode()); - $this->assertEquals('text/json', $result->getHeader('Content-Type')); + $this->assertEquals('application/json', $result->getHeader('Content-Type')); $data = json_decode($result->getBody(), true); $pageData = $data[$page1->ID]; $this->assertEquals(0, $pageData['ParentID']); @@ -253,7 +253,7 @@ class LeftAndMainTest extends FunctionalTest { // check subpage $result = $this->get('LeftAndMainTest_Controller/updatetreenodes?ids='.$page31->ID); $this->assertEquals(200, $result->getStatusCode()); - $this->assertEquals('text/json', $result->getHeader('Content-Type')); + $this->assertEquals('application/json', $result->getHeader('Content-Type')); $data = json_decode($result->getBody(), true); $pageData = $data[$page31->ID]; $this->assertEquals($page3->ID, $pageData['ParentID']); @@ -263,14 +263,14 @@ class LeftAndMainTest extends FunctionalTest { // Multiple pages $result = $this->get('LeftAndMainTest_Controller/updatetreenodes?ids='.$page1->ID.','.$page2->ID); $this->assertEquals(200, $result->getStatusCode()); - $this->assertEquals('text/json', $result->getHeader('Content-Type')); + $this->assertEquals('application/json', $result->getHeader('Content-Type')); $data = json_decode($result->getBody(), true); $this->assertEquals(2, count($data)); // Invalid IDs $result = $this->get('LeftAndMainTest_Controller/updatetreenodes?ids=-3'); $this->assertEquals(200, $result->getStatusCode()); - $this->assertEquals('text/json', $result->getHeader('Content-Type')); + $this->assertEquals('application/json', $result->getHeader('Content-Type')); $data = json_decode($result->getBody(), true); $this->assertEquals(0, count($data)); } diff --git a/control/PjaxResponseNegotiator.php b/control/PjaxResponseNegotiator.php index 5514326a0..d316800f3 100644 --- a/control/PjaxResponseNegotiator.php +++ b/control/PjaxResponseNegotiator.php @@ -93,7 +93,7 @@ class PjaxResponseNegotiator { } } $response->setBody(Convert::raw2json($responseParts)); - $response->addHeader('Content-Type', 'text/json'); + $response->addHeader('Content-Type', 'application/json'); return $response; } diff --git a/tests/control/PjaxResponseNegotiatorTest.php b/tests/control/PjaxResponseNegotiatorTest.php index 496ef1ebe..6fa207560 100644 --- a/tests/control/PjaxResponseNegotiatorTest.php +++ b/tests/control/PjaxResponseNegotiatorTest.php @@ -29,7 +29,7 @@ class PjaxResponseNegotiatorTest extends SapphireTest { )); $request = new SS_HTTPRequest('GET', '/'); $request->addHeader('X-Pjax', 'myfragment,otherfragment'); - $request->addHeader('Accept', 'text/json'); + $request->addHeader('Accept', 'application/json'); $response = $negotiator->respond($request); $json = json_decode( $response->getBody()); $this->assertObjectHasAttribute('myfragment', $json); @@ -46,7 +46,7 @@ class PjaxResponseNegotiatorTest extends SapphireTest { $request = new SS_HTTPRequest('GET', '/'); $request->addHeader('X-Pjax', 'alpha'); - $request->addHeader('Accept', 'text/json'); + $request->addHeader('Accept', 'application/json'); $response = $negotiator->setFragmentOverride(array('beta'))->respond($request); $json = json_decode( $response->getBody());