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

Suggestion: allow single extension in ng-accept #573

Closed
redders6600 opened this issue Feb 17, 2015 · 2 comments
Closed

Suggestion: allow single extension in ng-accept #573

redders6600 opened this issue Feb 17, 2015 · 2 comments

Comments

@redders6600
Copy link

With Chrome:

  • using ng-accept="'*.apk'" will allow selecting.apk` files but the file picker doesn't filter anything
  • using ng-accept="'.apk'" filters the file picker, but rejects.apk` files after it's picked.
  • using ng-accept="'.apk," (note comma) will allow selecting .apk files with a filtered file picker dialog, this is what ng-accept="'.apk'" should do.

I believe this is because the globStringToRegex function is used to filter out files after they're accepted. Given .apk isn't a glob, globStringToRegex converts it into a regex like /^\.apk$/, which obviously doesn't match apk files with a filename.

I suggest adding another line to the globStringToRegex function, which (if no comma is present) checks for the first character being a ., and creates a wildcarded glob like so:

function globStringToRegex(str) {
    if (str.length > 2 && str[0] === '/' && str[str.length -1] === '/') {
        return str.substring(1, str.length - 1);
    }
    var split = str.split(','), result = '';
    if (split.length > 1) {
        for (var i = 0; i < split.length; i++) {
            if (split[i].indexOf('.') == 0) {
                split[i] = '*' + split[i];
            }
            result += '(' + globStringToRegex(split[i]) + ')';
            if (i < split.length - 1) {
                result += '|'
            }
        }
    } else if (str[0] === '.') {  // .ext
      result += globStringToRegex( '*' + str ); 
    } else {
        result = '^' + str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + '-]', 'g'), '\\$&') + '$';
        result = result.replace(/\\\*/g, '.*').replace(/\\\?/g, '.');
    }
    return result;
}

This means globStringToRegex('.apk') === "^\.apk$" which is much more useful.

danialfarid pushed a commit that referenced this issue Feb 17, 2015
@danialfarid
Copy link
Owner

fixed in version 3.0.5

@redders6600
Copy link
Author

Speedy!

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