FIX txt/json is not a valid content type

This commit is contained in:
Daniel Hensby 2018-08-13 12:16:42 +01:00
parent a6cab8850d
commit 5f48b3e5d2
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
5 changed files with 9 additions and 9 deletions

View File

@ -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);
}

View File

@ -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 {

View File

@ -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));
}

View File

@ -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;
}

View File

@ -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());