mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX txt/json is not a valid content type
This commit is contained in:
parent
a6cab8850d
commit
5f48b3e5d2
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user