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

Spaces in filenames causes 400 bad request #170

Closed
frijj2k opened this issue Jul 23, 2019 · 7 comments · Fixed by #171
Closed

Spaces in filenames causes 400 bad request #170

frijj2k opened this issue Jul 23, 2019 · 7 comments · Fixed by #171

Comments

@frijj2k
Copy link

frijj2k commented Jul 23, 2019

When using Laravel, php-tus and Uppy, everything is working fine until I drag-drop a file that has space characters in the filename.

I have autoProceed set to true and the file attempts to be uploaded but tus-php returns a 400 bad request. If I remove the space(s) from the filename and retry it works without issue.

I followed the Laravel/Lumen integration guide so my routes files looks like:

Route::any('/tus/{any?}', function () {
    $response = app('tus-server')->serve();

    return $response->send();
})->where('any', '.*');

My TusServiceProvider.php is as follow:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use TusPhp\Tus\Server as TusServer;
use TusPhp\Events\TusEvent;

class TusServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('tus-server', function ($app) {
            $server = new TusServer('file'); //('redis'); // Leave empty for file based cache

            $server
                ->setApiPath('/tus') // tus server endpoint.
                ->setUploadDir(storage_path('app/uploads')); // uploads dir.

            return $server;
        });
    }
}

And my Javascript is as follow:

        var uppy = Uppy({
            id: 'uppy',
            autoProceed: true,
            allowMultipleUploads: true,
            debug: false,
            restrictions: {
                maxFileSize: null,
                maxNumberOfFiles: null,
                minNumberOfFiles: null,
                allowedFileTypes: null
            }
        })
        .use(Tus, {
            endpoint: '/tus/',
            resume: true,
            autoRetry: true,
            retryDelays: [0, 1000, 3000, 5000],
            chunkSize: 2000000 // bytes (so 2MB)
        })
        .use(Dashboard, {
            target: '#drag-drop-area',
            inline: true,
            showProgressDetails: true,
            showLinkToFileUploadResult: false
        });
@frijj2k
Copy link
Author

frijj2k commented Jul 23, 2019

Ok so I managed to get it to work by changing the filename before being uploaded via:

            onBeforeFileAdded: (currentFile, files) => {
                var modifiedFile = Object.assign({}, currentFile, {
                    name: currentFile.name.replace(" ", "-") //clean spaces
                });
                uppy.info(modifiedFile);
                return modifiedFile;
            }

In my Uppy config however this is not ideal as I would like to preserve the original filename. I guess I could add the original name to the meta data and convert it back at the server end once fully uploaded but still wondering if there's a way to avoid all this extra hassle?

@ankitpokhrel
Copy link
Owner

@frijj2k this issue seems to be introduced by the latest change here - #168

You can use old release (1.0.8) for now, I will fix it as soon as I get a chance. PRs are welcome.

@Steveb-p
Copy link
Contributor

PRs are welcome.

@ankitpokhrel There you go :)

Yeah, spaces should not trigger validation error :) They should not allow one to break out of a directory.

@frijj2k
Copy link
Author

frijj2k commented Jul 24, 2019

Nice one, thank you! :)

@valentin-anamorphik
Copy link

valentin-anamorphik commented Feb 25, 2021

Same error with quote in filename.

Ex.
my-fileA'B.pdf

@Steveb-p
Copy link
Contributor

Same error with apostrophe in filename.

Ex.
my-fileA'B.pdf

Quotes are explicitly forbidden in the code.

I've taken a look what characters are actually forbidden in filesystems and quotes will fail on Windows. Apparently they are acceptable on Linux 🤔

https://stackoverflow.com/a/31976060/2424641

@ankitpokhrel should we relax the checks a bit?

@ankitpokhrel
Copy link
Owner

@Steveb-p There is an open issue to make this configurable. I am open to PR :)

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

Successfully merging a pull request may close this issue.

4 participants