Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for 'Uninitialized string offset: 0' when using Request's referer under PHP 7 #8795

Merged
merged 2 commits into from
May 10, 2016

Conversation

elboletaire
Copy link
Contributor

Fixes #8794

As said in the issue, I'm not sure about how I've fixed it. But let me know what could I change to improve it.

@elboletaire
Copy link
Contributor Author

Now I like it better. Let me know what do you think 😃

@codecov-io
Copy link

codecov-io commented May 9, 2016

Current coverage is 92.89%

Merging #8795 into master will increase coverage by +<.01%

@@             master      #8795   diff @@
==========================================
  Files           363        363          
  Lines         27141      27143     +2   
  Methods        3206       3206          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          25212      25214     +2   
  Misses         1929       1929          
  Partials          0          0          

Powered by Codecov. Last updated by 6a463bb...c826a2b

@ADmad ADmad added this to the 3.2.9 milestone May 9, 2016
@ADmad ADmad added the defect label May 9, 2016
@ADmad
Copy link
Member

ADmad commented May 9, 2016

This issue looks similar to the fix done for 2.x 3ad68db

That code looks much cleaner.

@elboletaire
Copy link
Contributor Author

Yup, seems exactly the same issue. With that code you mean the one by @markstory, right?

If so, let me change it.

@ADmad
Copy link
Member

ADmad commented May 9, 2016

Yes I meant the code in commit I linked :)

@elboletaire
Copy link
Contributor Author

Done :)

@ADmad
Copy link
Member

ADmad commented May 9, 2016

Please squash the commits.

@elboletaire
Copy link
Contributor Author

Sure. BTW, on my first commit I was checking for empty and wasn't necessary. Something like this would be enough:

$ref = substr($ref, strlen($base)) ?: '/';
if ($ref[0] !== '/') {
    $ref = '/' . $ref;
}

pd. I'm squashing

@elboletaire
Copy link
Contributor Author

Done :)

@@ -547,6 +547,9 @@ public function referer($local = false)
if (!empty($ref) && !empty($base)) {
if ($local && strpos($ref, $base) === 0) {
$ref = substr($ref, strlen($base));
if (empty($ref)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should use strlen()? empty() eats '0'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, you're right. I've changed it in a52a8d1 adding an assertion for it too.

@markstory markstory merged commit 5df0413 into cakephp:master May 10, 2016
@markstory
Copy link
Member

Thanks 👍

@elboletaire
Copy link
Contributor Author

You're welcome, as always! 😃

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

Successfully merging this pull request may close these issues.

'Uninitialized string offset: 0' when using request->referer coming from home page (/) under php7
4 participants