Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/94'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Nov 14, 2017
2 parents 44be8e9 + df5d1f3 commit d9da8a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ All notable changes to this project will be documented in this file, in reverse
- [#86](https://github.com/zfcampus/zf-content-negotiation/pull/86) makes
zend-console a suggested dependency.

- [#88](https://github.com/zfcampus/zf-content-negotiation/pull/88) updates how
the `ContentTypeListener` decides how to parse incoming content when no
`Content-Type` header is present. If the content begins with a `{` or `[`
character, it will now parse it as JSON instead of as form data.

### Deprecated

- Nothing.
Expand Down
9 changes: 8 additions & 1 deletion src/ContentTypeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ public function __invoke(MvcEvent $e)
break;
}

parse_str($content, $bodyParams);
// Try to assume JSON if content starts like JSON and no explicit Content-Type was provided
if (! $bodyParams && in_array($content[0], ['{', '['], true)) {
$bodyParams = $this->decodeJson($content);
}

if (! $bodyParams || $bodyParams instanceof ApiProblemResponse) {
parse_str($content, $bodyParams);
}
break;
default:
break;
Expand Down
6 changes: 5 additions & 1 deletion test/ContentTypeListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,12 @@ public function testOnFinishWillRemoveAnyUploadFilesUploadedByTheListener()
$p->setAccessible(true);
$p->setValue($this->listener, $tmpDir);

if (strpos(PHP_OS, 'Darwin') !== false) {
$tmpFile = '/private/var/' . $tmpFile;
}

$this->listener->onFinish($event);
$this->assertFalse(file_exists($tmpFile));
$this->assertFileNotExists($tmpFile);
}

public function testOnFinishDoesNotRemoveUploadFilesTheListenerDidNotCreate()
Expand Down

0 comments on commit d9da8a2

Please sign in to comment.