Skip to content

Additionals: fixed the accept method regex, regex should be escaped #1373

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

Closed
wants to merge 7 commits into from

Conversation

mishal
Copy link
Contributor

@mishal mishal commented Jan 14, 2015

Fixes #1243

@jzaefferer
Copy link
Collaborator

That looks decent. Could you add unit tests for this method? Even if they need to be wrapped in a feature detect for element.files, that would still be a big improvement over no coverage at all.

@mishal
Copy link
Contributor Author

mishal commented Jan 26, 2015

I tried to create test for it, but I'm not sure how to mock the file input functionality, since JS cannot update the value if the file input...

Do you have an idea how to test it?

@jzaefferer
Copy link
Collaborator

You could start with an input of type file, select that from the DOM, then overwrite the files property. Not sure if its writable, but if it is, this might work (not tested):

<input type="file" id="accept-input">
var element = $( "#accept-input" )[0];
// Assign something here for each assertion, not sure what the right format is
element.files = [ "myfile.docx" ];
ok( $.validator.method.accept( null, element, "docx" ), "something something is valid" );

I have no idea what the right format for files and param are, but I hope this helps. Thanks for looking into it!

@mishal
Copy link
Contributor Author

mishal commented Jan 27, 2015

Hmmm, the input property files is readonly for security reasons.

@jzaefferer
Copy link
Collaborator

Makes sense. Maybe we can mock the DOM element from scratch? Along with the files property it needs to be pass the this.optional() check and respond to $(element).attr("type") with "file".

@mishal
Copy link
Contributor Author

mishal commented Jan 27, 2015

I had the same idea.. I will try it :)

@mishal
Copy link
Contributor Author

mishal commented Jan 29, 2015

I've just created the tests, the last one is for invalid mime type. I'm not sure if the last one check for dependency-mismatch is ok...

validator;

// dummy DOM element
input.type = "file";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define these above, its fine to reference a variable defined in the same multi declaration.

@jzaefferer
Copy link
Collaborator

Thanks for the update! This is promising, but needs a bit of refactoring and cleanup.

@mishal
Copy link
Contributor Author

mishal commented Jan 29, 2015

Yes, you are right, this is raw version, I will clean it up.

@jzaefferer
Copy link
Collaborator

Never noticed the new commits until now - there are no notifications for pushes... reviewing again.

name: filename,
size: 500001,
type: mimeType
}, fileList = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a line break after the comma

@jzaefferer
Copy link
Collaborator

Still a few minor issues with the tests. Please let me know when you push new commits, so that I can review them immediately.

@mishal
Copy link
Contributor Author

mishal commented Feb 18, 2015

ping @jzaefferer

@jzaefferer
Copy link
Collaborator

Hope thats more clear. I'll be away the next few days, will check again next week.

@mishal
Copy link
Contributor Author

mishal commented Mar 9, 2015

Sorry for the delay, I had urgent work to do.

ping @jzaefferer

@mishal
Copy link
Contributor Author

mishal commented Mar 24, 2015

@jzaefferer did you have a chance to see this?

@jzaefferer
Copy link
Collaborator

Sorry for the delay. Could you rebase this against master? Thanks.

@twolfson
Copy link

@mishal As @jzaefferer requested in #1512, I have squashed/rebased this PR into #1531. Authorship and the original diff should be maintained but now in 1 commit and on top of the latest master.

@mishal
Copy link
Contributor Author

mishal commented Sep 9, 2015

Thanks, closing, please merge #1531

@mishal mishal closed this Sep 9, 2015
staabm pushed a commit that referenced this pull request Nov 26, 2015
This adds support for types like "application/epub+zip"
which contain regex meta characters.

Fixes #1243, #1258. Closes #1531, #1373. Refs #1512.
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

Successfully merging this pull request may close these issues.

"accept" validator not working on application/epub+zip mimetype
3 participants