dir2cast icon indicating copy to clipboard operation
dir2cast copied to clipboard

Fix double forward slash in the beginning of the path

Open rromanw opened this issue 2 years ago • 3 comments

When there are two froward slashes in the beginning (it happens) it breaks the paths.

rromanw avatar Apr 18 '22 10:04 rromanw

Hey @rromanw thanks so much for the contribution!

What's the consequence of having the double slash? It's usually harmless, so where is it causing trouble?

Do you have any steps to reproduce, or perhaps even a test case, or just an example?

From your patch, I'm wary of what happens when something is a symlink, because realpath() also resolves symlinks, which doesn't sound like it would be intentional. And indeed it causes the tests to fail on MacOS (weirdly not on Linux) as you can see.

It might be a better fix to do something like str_replace('//', '/', ...) - but I'm keen to know more about what the real problem is.

ben-xo avatar Apr 18 '22 17:04 ben-xo

Also, MP3_BASE is used to create default MP3_DIR, and MP3_DIR is used to compare with DOCUMENT_ROOT to check that we're allowed to read from it for security reasons. So it should match what's in DOCUMENT_ROOT.

This behaviour could probably do with some additional unit tests because that assumption might be totally wrong these days (it was usually true 12 years ago, and I think it might be usually false now)…

ben-xo avatar Apr 18 '22 17:04 ben-xo

Hey @rromanw are you able to give me an example of how the double forward slash occurs, and some more information about your setup? Are you using nginx and php-fpm in docker, or some other setup? Can you give me an example of the MP3_BASE with the double forward slash?

ben-xo avatar Apr 25 '22 18:04 ben-xo

I think I've fixed this properly in #66

ben-xo avatar Oct 17 '22 20:10 ben-xo