Skip to content

Commit

Permalink
Resolves #169: include non-struct json body as _body argument to re…
Browse files Browse the repository at this point in the history
…sources
  • Loading branch information
Adam Tuttle committed Jan 21, 2014
1 parent 199f52d commit c26fae8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 8 additions & 3 deletions core/api.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,15 @@
<cfset throwError(msg="Input JSON is not well formed: #requestObj.body#") />
</cfif>
<cfset local.tmp = deserializeJSON(requestObj.body) />
<cfif structKeyExists(local.tmp, "data")>
<cfset requestObj.bodyArgs = local.tmp.data />
<cfif not isStruct(local.tmp)>
<cfset requestObj.bodyArgs = {} />
<cfset requestObj.bodyArgs['_body'] = local.tmp />
<cfelse>
<cfset requestObj.bodyArgs = local.tmp />
<cfif structKeyExists(local.tmp, "data")>
<cfset requestObj.bodyArgs = local.tmp.data />
<cfelse>
<cfset requestObj.bodyArgs = local.tmp />
</cfif>
</cfif>
<cfset requestObj.queryString = cgi.query_string />
<cfelseif findNoCase("multipart/form-data", requestObj.contentType)>
Expand Down
10 changes: 10 additions & 0 deletions tests/tests/TestCore.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,16 @@
assertTrue(local.result.responseHeader["Access-Control-Allow-Headers"] contains "pigeon");
assertTrue(local.result.responseHeader["Access-Control-Allow-Headers"] contains "man-bear-pig");
}

function non_struct_json_body_sent_to_resource_as_underscore_body(){
//see: https://github.com/atuttle/Taffy/issues/169
local.result = apiCall("post", "/echo/5", "[1,2,3]");
debug(local.result);
local.response = deserializeJSON(local.result.fileContent);
assertTrue(structKeyExists(local.response, "_body"));
assertTrue(isArray(local.response._body));
assertTrue(arrayLen(local.response._body) == 3);
}
</cfscript>


Expand Down

0 comments on commit c26fae8

Please sign in to comment.