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]: Unable to open a file with question mark #1190

Closed
nickdekruijk opened this issue Dec 9, 2024 · 2 comments
Closed

[Bug]: Unable to open a file with question mark #1190

nickdekruijk opened this issue Dec 9, 2024 · 2 comments
Labels

Comments

@nickdekruijk
Copy link

Platform

macOS

Operating system version

MacOS Sequoia 15.1.1 (24B91)

System architecture

ARM64 (M1, M2, etc)

Herd Version

1.13.0 (Build 37)

PHP Version

PHP 8.3.14 (cli) (built: Nov 21 2024 08:25:00) (NTS)

Bug description

When I have a file with a questionmark in my Laravel app public folder, e.g. Road?.jpg and I try to open http://site.test/Road%3F.jpg this won't work. I will return a 404 page but not the nice page Laravel usually returns but a plain text 404 not found from Nginx itself. When the site/file is uploaded to a real server (a Forge server in my case) it works just fine. Might be some herd/nginx config thing locally?

Steps to reproduce

Create a new Herd site, place a jpeg image file called 'Road?.jpg' in the (public) root and try to open sitename.test/Road%3F.jpg

Relevant log output

For some reason the /Users/xxx/Library/Application\ Support/Herd/Log/nginx-error.log shows:

2024/12/09 11:30:29 [error] 27821#2419520: *14 "Users/xxx/Documents/Sites/sitename/Road/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: sitename.test, request: "GET /Road%3F.jpg HTTP/2.0", upstream: "fastcgi://unix:/Users/xxx/Library/Application Support/Herd/herd.sock", host: "sitename.test"

But only when I add %3F in url, looks like Herd/Nginx is parsing %3F as a regular ? questionmark
@issuelabeler issuelabeler bot added the macOS label Dec 9, 2024
@mpociot
Copy link
Member

mpociot commented Dec 9, 2024

This seems to be an issue in how nginx handles the static files url encoding.

I need to investigate if this is going to cause any trouble down the line, but in the meantime you can fix this by using a local valet driver.
Just put this code in a file called LocalValetDriver.php in the root of your project 👍

<?php

use Valet\Drivers\LaravelValetDriver;

class LocalValetDriver extends LaravelValetDriver
{
    public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
    {
        $staticFilePath = parent::isStaticFile($sitePath, $siteName, $uri);

        return $staticFilePath ? urlencode($staticFilePath) : false;
    }
}

@nickdekruijk
Copy link
Author

nickdekruijk commented Dec 9, 2024

Thanks @mpociot! Had to use rawurlencode in the isStaticFile function for folders containing quotes. But this works for now. Hope you can find a more solid solution.

@mpociot mpociot closed this as completed Dec 18, 2024
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