BUGFIX #5862 JSON output of JSONDataFormatter now uses quotes for keys to be safer (from r108409)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112729 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-18 22:55:06 +00:00
parent 066bf90f02
commit 3ddd5647a1

View File

@ -63,7 +63,7 @@ class JSONDataFormatter extends DataFormatter {
} else { } else {
$href = Director::absoluteURL(self::$api_base . "$className/$id/$relName"); $href = Director::absoluteURL(self::$api_base . "$className/$id/$relName");
} }
$jsonParts[] = "$relName : { \"className\" : \"$relClass\", \"href\" : \"$href.json\", \"id\" : \"{$obj->$fieldName}\" }"; $jsonParts[] = "\"$relName\" : { \"className\" : \"$relClass\", \"href\" : \"$href.json\", \"id\" : \"{$obj->$fieldName}\" }";
} }
foreach($obj->has_many() as $relName => $relClass) { foreach($obj->has_many() as $relName => $relClass) {
@ -80,7 +80,7 @@ class JSONDataFormatter extends DataFormatter {
$href = Director::absoluteURL(self::$api_base . "$relClass/$item->ID"); $href = Director::absoluteURL(self::$api_base . "$relClass/$item->ID");
$jsonInnerParts[] = "{ \"className\" : \"$relClass\", \"href\" : \"$href.json\", \"id\" : \"{$obj->$fieldName}\" }"; $jsonInnerParts[] = "{ \"className\" : \"$relClass\", \"href\" : \"$href.json\", \"id\" : \"{$obj->$fieldName}\" }";
} }
$jsonParts[] = "$relName : [\n " . implode(",\n ", $jsonInnerParts) . " \n ]"; $jsonParts[] = "\"$relName\" : [\n " . implode(",\n ", $jsonInnerParts) . " \n ]";
} }
foreach($obj->many_many() as $relName => $relClass) { foreach($obj->many_many() as $relName => $relClass) {
@ -97,7 +97,7 @@ class JSONDataFormatter extends DataFormatter {
$href = Director::absoluteURL(self::$api_base . "$relClass/$item->ID"); $href = Director::absoluteURL(self::$api_base . "$relClass/$item->ID");
$jsonInnerParts[] = " { \"className\" : \"$relClass\", \"href\" : \"$href.json\", \"id\" : \"{$obj->$fieldName}\" }"; $jsonInnerParts[] = " { \"className\" : \"$relClass\", \"href\" : \"$href.json\", \"id\" : \"{$obj->$fieldName}\" }";
} }
$jsonParts[] = "$relName : [\n " . implode(",\n ", $jsonInnerParts) . "\n ]"; $jsonParts[] = "\"$relName\" : [\n " . implode(",\n ", $jsonInnerParts) . "\n ]";
} }
} }