Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for filename with quotes in multipart

I'm trying to parse a multipart/form-data request properly, it works unless the file that is beeing uploaded contains double quotes.

The request looks like (excerpt from wireshark):

Content-Disposition: form-data; name="file"; filename="b'e\"e.JPG"

So the file is actually called b'e"e.jpg on my local filesystem. The browser escapes the quotes properly.

I want to grab the filename b'e\"e.JPG out of this string.

I found a regex for grabbing quoted strings with escaped quotes inside:

/"[^"\\]*(\\.[^"\\]*)*"/i

(source http://www.regular-expressions.info/regexbuddy/stringescapedmulti.html)

The regex works perfectly when applied on the string "b'e\"e.JPG" but when I try to scope it only on the filename= part, like:

/filename="[^"\\]*(\\.[^"\\]*)*"/i

I won't get any results.

Any help would be really appreciated

Edit:

I'm working with JavaScript, so I put the regex on js fiddle: http://jsfiddle.net/hDBcs/

Thanks!

Simon

like image 436
sled Avatar asked Oct 10 '22 10:10

sled


1 Answers

Possibly the problem is that you are not using brackets in order to get needed parts:

/filename="([^"\\]*(?:\\.[^"\\]*)*)"/i
like image 68
Karolis Avatar answered Dec 11 '22 20:12

Karolis