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

Undefined offset in Client.php __call() caused by empty URI arguments #43

Closed
danielmreck opened this issue May 7, 2018 · 3 comments
Closed
Labels

Comments

@danielmreck
Copy link

danielmreck commented May 7, 2018

Hello,

When certain unusual URI queries are passed to phpSmug, we sometimes receive the following error:

PHP Notice: Undefined offset: 1 in /vendor/lildude/phpsmug/lib/phpSmug/Client.php on line 139

This is caused when contiguous '&' characters appear in the query statement, effectively creating empty arguments, as seen here between arg1 and arg2:

...?arg1=value1&&arg2=value2

The PHP notice can be corrected by stripping out these empty arguments, by inserting the following at line 137 in phpsmug/lib/phpSmug/Client.php, just before the foreach loop:
$pairs = array_diff($pairs,['']);

Here is the context:

# Cater for any args passed in via `?whatever=foo`
if (strpos($url, '?') !== false) {
  $pairs = explode('&', explode('?', $url)[1]);
  $pairs = array_diff($pairs,['']);   // remove empty args caused by adjacent &s in $url
  foreach ($pairs as $pair) {
    list($key, $value) = explode('=', $pair);
    $this->request_options['query'][$key] = $value;
  }
}

I'm sorry I can't formally fork and unit test this right now, although this fix is working in my project.

@lildude
Copy link
Owner

lildude commented May 14, 2018

Ooof, nice catch. I didn’t consider double &. Should be a simple change. I’ll whip up a PR when I’ve got a free moment.

@stale
Copy link

stale bot commented May 28, 2018

This issue has been automatically marked as stale because it has not had activity in 14 days. It will be closed in 2 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 28, 2018
@lildude
Copy link
Owner

lildude commented May 28, 2018

Down stalebot.

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

No branches or pull requests

2 participants