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

Since 1.3.1 : Notice: Uninitialized string offset: 0 in ../ContentTypeListener.php on line 105 #96

Closed
NicolasCayet opened this issue Nov 15, 2017 · 1 comment

Comments

@NicolasCayet
Copy link

Hello,

After trying to use the last 1.3.1 version early released, i issued with this error notice :
Notice: Uninitialized string offset: 0 in ../vendor/zfcampus/zf-content-negotiation/src/ContentTypeListener.php on line 105

This notice appears on PATCH / PUT / DELETE request, whenever you did not pass any HTTP body − which is possible following standards.

As we can see within the code, trying to auto-detect JSON format in body when no Content-Type is provided is fine, but it must first detect if any body has been provided...

if (! $bodyParams && in_array($content[0], ['{', '['], true)) {

weierophinney added a commit to weierophinney/zf-content-negotiation that referenced this issue Nov 15, 2017
As reported in zfcampus#96, since zfcampus#94 and the 1.3.1 release, if the body content
for a PUT, PATCH, or DELETE call is empty, an "Uninitialized string
offset: 0" notice is raised.

This patch does the following:

- Adds tests missing from the original patch created for zfcampus#94, verifying
  that JSON deserialization occurs for those HTTP methods if the content
  looks like JSON but no Content-Type header was present.
- Adds tests demonstrating that _empty_ content in those same situations
  will not result in an error, and a fix to the code to make that test
  pass.
weierophinney added a commit to weierophinney/zf-content-negotiation that referenced this issue Nov 15, 2017
As reported in zfcampus#96, since zfcampus#94 and the 1.3.1 release, if the body content
for a PUT, PATCH, or DELETE call is empty, an "Uninitialized string
offset: 0" notice is raised.

This patch adds tests missing from the original patch created for zfcampus#94,
verifying that JSON deserialization occurs for those HTTP methods if the
content looks like JSON but no Content-Type header was present. The new
cases also include scenarios where no content is present. A fix is
introduced to the `ContentTypeListener` to ensure the notice is no
longer raised.
@weierophinney
Copy link
Member

Fixed with version 1.3.2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants