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

Bug: 'method' is an empty string in PATH_INFO causes Unhandled Exception #2965

Closed
willnode opened this issue May 10, 2020 · 4 comments · Fixed by #2978
Closed

Bug: 'method' is an empty string in PATH_INFO causes Unhandled Exception #2965

willnode opened this issue May 10, 2020 · 4 comments · Fixed by #2978
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@willnode
Copy link
Contributor

willnode commented May 10, 2020

Describe the bug

When running php spark serve, I noticed that if I set this to PATH_INFO

public $uriProtocol = 'REQUEST_URI';

And navigate to URL localhost:8080/home/, causes ErrorException: Unitialized string offset: 0 in

if (! class_exists($this->controller, true) || $this->method[0] === '_')

Because $this->method is "".

CodeIgniter 4 version
Version 4.0.3 release (in latest develop, it's just shows 404 page, skipping the actual error and throws PageNotFoundException::forMethodNotFound, probably because recent changes in error reporting level? sorry I forgot that by default CI is in production mode)

Affected module(s)
None, I think.

Expected behavior, and steps to reproduce if appropriate
It should render the same page as localhost:8080/ or localhost:8080/home/index

Context

  • OS: Windows 10 64 bit
  • PHP version 7.3.9
@willnode willnode added the bug Verified issues on the current code behavior or pull requests that will fix them label May 10, 2020
@willnode
Copy link
Contributor Author

There's a workaround that works for me:

public function methodName(): string
{
return $this->translateURIDashes
? str_replace('-', '_', $this->method)
: $this->method;
}

I changed them into:

	public function methodName(): string
	{
		return ($this->translateURIDashes
			? str_replace('-', '_', $this->method)
			: $this->method) ?: 'index';
	}

However I'm not sure if this a good bugfix as a PR.

@willnode
Copy link
Contributor Author

Additional info: I'm using PATH_INFO because I found it plays nice and well to remove /public in my local apache server using .htaccess file to root project.

@nyufeng
Copy link
Contributor

nyufeng commented May 12, 2020

Default, method is 'index'.
image

@willnode
Copy link
Contributor Author

willnode commented May 12, 2020

@Instrye sorry I forgot to mention that it happens when you add a trailing slash

image

Edit: In development mode

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants