Skip to content

Commit

Permalink
fix json parse error on empty headers (#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Coalwell committed Jun 13, 2019
1 parent c08969c commit 7357332
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changes/nextrelease/changelog_fix_json_parse_header.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "Api",
"description": "Fix json parse error when extracting header"
}
]
17 changes: 14 additions & 3 deletions src/Api/Parser/AbstractRestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,21 @@ private function extractHeader(
return;
}
case 'string':
if ($shape['jsonvalue']) {
$value = $this->parseJson(base64_decode($value), $response);
try {
if ($shape['jsonvalue']) {
$value = $this->parseJson(base64_decode($value), $response);
}

// If value is not set, do not add to output structure.
if (!isset($value)) {
return;
}
break;
} catch (\Exception $e) {
//If the value cannot be parsed, then do not add it to the
//output structure.
return;
}
break;
}

$result[$name] = $value;
Expand Down
30 changes: 30 additions & 0 deletions tests/Api/test_cases/protocols/output/rest-json.json
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,36 @@
"headers": {"X-Amz-Foo": "eyJGb28iOiJCYXIifQ=="},
"body": ""
}
},
{
"given": {
"output": {
"shape": "OutputShape"
},
"name": "OperationName"
},
"result": {
"Attr": {}
},
"response": {
"status_code": 200,
"headers": {"X-Amz-Foo": "e30="},
"body": ""
}
},
{
"given": {
"output": {
"shape": "OutputShape"
},
"name": "OperationName"
},
"result": {},
"response": {
"status_code": 200,
"headers": {"X-Amz-Foo": ""},
"body": ""
}
}
]
}
Expand Down

0 comments on commit 7357332

Please sign in to comment.