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

Possibility to upload file with filtered extension #648

Closed
ArtemLikhenko opened this issue Nov 14, 2012 · 0 comments
Closed

Possibility to upload file with filtered extension #648

ArtemLikhenko opened this issue Nov 14, 2012 · 0 comments

Comments

@ArtemLikhenko
Copy link

I've found out that for filter { title: 'Image files', extensions: 'jpg,gif,png,jpeg' } user can upload file with "wrong" extension, for example next one "example.jpg2000" , but it should be ignored because extension ".jpg2000" is not included in filter. So, I've made some investigation and found following code:

if (filters && filters.length) {
    extensionsRegExp = [];

        plupload.each(filters, function(filter) {
        plupload.each(filter.extensions.split(/,/), function(ext) {
        if (/^\s*\*\s*$/.test(ext)) {
            extensionsRegExp.push('\\.*');
        } else {
            extensionsRegExp.push('\\.' + ext.replace(new RegExp('[' + ('/^$.*+?|()[]{}\\'.replace(/./g, '\\$&')) + ']', 'g'), '\\$&'));
        }
    });
   });

extensionsRegExp = new RegExp(extensionsRegExp.join('|') + '$', 'i');
}

The code produces following regular expression: /.jpg|.gif|.png|.jpeg$/i , but in my opinion it should be /.jpg$|.gif$|.png$|.jpeg$/i.

So to fix this bug I suggest to replace this string:

extensionsRegExp = new RegExp(extensionsRegExp.join('|') + '$', 'i');

by

extensionsRegExp = new RegExp(extensionsRegExp.join('$|') + '$', 'i');

Thanks,
Artem

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