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

Problem when dealing with "Content-Disposition" header at Mojo::Message? #642

Closed
s-murata opened this issue Jul 3, 2014 · 4 comments
Closed

Comments

@s-murata
Copy link

s-murata commented Jul 3, 2014

If a backslash(\) exists at the end point of a uploaded file name, a parsed file name is include a double quote(").
I seem a problem exists in in Mojo::Message::parse_formdata method.

    my ($filename) = $disposition =~ /[; ]filename\s*=\s*"?((?:\\"|[^"])*)"?/i;

For example, when the file name is foo\"bar\, and Content-Disposition header includes ; filename="foo\"bar\", that regular expression matches foo\"bar\".
A $name variable has a same problem too.

    my ($name) = $disposition =~ /[; ]name\s*=\s*"?((?:\\"|[^";])+)"?/i;

My proposal is ...

    my ($filename) = $disposition =~ /[; ]filename\s*=\s*"?((?:\\"(?!\s|\z)|[^"])*)"?/i;

and

    my ($name) = $disposition =~ /[; ]name\s*=\s*"?((?:\\"(?!;|\s|\z)|[^";])+)"?/i;

Any good idea?

@kraih
Copy link
Member

kraih commented Jul 3, 2014

Your proposed change breaks existing tests.

@s-murata
Copy link
Author

s-murata commented Jul 3, 2014

Sorry, exactly. Break if file name include white spaces.

I'll think alternative.

@kraih kraih closed this as completed in f6d804a Jul 3, 2014
@kraih
Copy link
Member

kraih commented Jul 3, 2014

Thanks, fixed.

@s-murata
Copy link
Author

s-murata commented Jul 3, 2014

Thanks for your commit.
I was a bit late:)

    (undef, my $filename) = $disposition =~ /[; ]filename\s*=\s*("?)((?:\\"|[^"])*)\1/i;

Your commit is better and more simple. Thanks.

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

No branches or pull requests

2 participants