Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Always parse body if inputFormat is set #213

Open
wants to merge 2 commits into from

1 participant

@dshafik
Owner

This was originally written as it was to avoid a BC issue, but it's possible to miss JSON input with more complex JSON structures.

{
    "var": {
        "test": false,
        "foo": "bar", 
        "baz": 0, 
        "bing": []
    },
}

This will result in the broken behavior.

If you are sending Content-Type: application/json, Content-Type: application/xml or similar, then you're probably wanting to send JSON or XML — I don't think this will be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2013
  1. @dshafik
  2. @dshafik
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 19 deletions.
  1. +7 −19 src/frapi/library/Frapi/Controller/Main.php
View
26 src/frapi/library/Frapi/Controller/Main.php
@@ -328,29 +328,14 @@ public function setParams(array $params)
{
// read the raw input to get the request body
$input = file_get_contents("php://input");
- parse_str($input, $puts);
$inputFormat = $this->inputFormat;
if(empty($inputFormat)) {
- $xmlJsonMatch = preg_grep('/\<|\{/i', array_keys($puts));
$inputFormat = $this->getFormat();
}
- /**
- * When doing parse_str("{json:string}") it creates an array like:
- * array(
- * "{json:string}" => ""
- * )
- *
- * If args are also present along with the body, they are in the array
- * before the body.
- *
- * Checks if the last argument is an empty string, this + inputForm is
- * indicative of the body needing parsing.
- */
- if (end($puts) == '' && !empty($inputFormat) || !empty($xmlJsonMatch)) {
+ if (!empty($inputFormat)) {
/* attempt to parse the input */
- reset($puts);
$requestBody = Frapi_Input_RequestBodyParser::parse(
$inputFormat,
$input
@@ -369,9 +354,12 @@ public function setParams(array $params)
$params = array_merge($params, $requestBody);
}
- } else if (!empty($puts)) {
- foreach ($puts as $put => $val) {
- $params[$put] = $val;
+ } else {
+ parse_str($input, $puts);
+ if (!empty($puts)) {
+ foreach ($puts as $put => $val) {
+ $params[$put] = $val;
+ }
}
}
Something went wrong with that request. Please try again.