Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow "accept" filetype validation to contain a blank among the accepted MIME types#1441

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
rskm1 wants to merge5 commits intojquery-validation:masterfromrskm1:patch-3

Conversation

rskm1
Copy link
Contributor

The backstory on this change is that on the Windows platform, if you install WinRAR (or WinZip or 7Zip), those tools will very often screw up the extension-to-mimetype mapping of the OS, so the file object's .type has an EMPTY STRING value when it gets here for validation.

The intuitive thing to do is support EMPTY STRING by just putting a comma prefix on the accept value, such as "accept=',application/zip,application/x-zip-compressed'". But unfortunately that turns the regex into a mess that will accept ANY type.

This patch handles the case of a blank "accept" type before RegExp has to.

(Also, the RegExp has a period where I think a "." should be, but I made that change in a separate pull req since it's unlikely to be controversial, whereas this one may raise some eyebrows and require further discussion).

The backstory on this change is that on the Windows platform, if you install WinRAR (or WinZip or 7Zip), those tools will very often screw up the extension-to-mimetype mapping of the OS, so the file object's .type has an EMPTY STRING value when it gets here for validation.The intuitive thing to do is support EMPTY STRING by just putting a comma prefix on the accept value, such as "accept=',application/zip,application/x-zip-compressed'".  But unfortunately that turns the regex into a mess that will accept ANY type.This patch handles the case of a blank "accept" type before RegExp has to.(Also, the RegExp has a period where I think a "\\." should be, but I made that change in a separate pull req since it's unlikely to be controversial, whereas this one may raise some eyebrows and require further discussion).
@rskm1rskm1 changed the titleUpdate accept.jsAllow "accept" filetype validation to contain a blank among the accepted MIME typesApr 22, 2015
@jzaefferer
Copy link
Collaborator

Thank you for the contribution. I've merged the other two PRs. This one is certainly more controversial. I don't like that its difficult to even reproduce the issue, so I can't really test this change. Since this is in the "additional" category, I'm okay with landing it anyway.

@staabm any thoughts on this?

@@ -14,11 +15,23 @@ $.validator.addMethod("accept", function(value, element, param) {
// If we are using a wildcard, make it regex friendly
typeParam = typeParam.replace(/\*/g, ".*");

// Allow checking for BLANK mimetype.
if (typeParam.match(/^\|/) || typeParam.match(/\|\|/)) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess this wont work when the EMPTY STRING is the last element in the param?

Copy link
Member

Choose a reason for hiding this comment

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

Do we also need to handle "space only" comma delimited values like a empty qualifier?

Update: scratch this note: spaces are allready strip when this line is reached.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Oooo, good catch! I overlooked the possibility of ending the parm with a comma separator, and that should definitely have the same effect as a double-comma or a comma prefix.

Let me see if I can figure out how to revise a pull req from this web interface...

Copy link
Member

Choose a reason for hiding this comment

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

Just do another commit at the same branch. We can squash it later when everything looks fine.

Could you also add a few unit tests?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done!

As for unit tests, I poked around in the tests directory and couldn't find any existing tests of the "accept" method. There are lots of tests for the "extension" method in /test/methods.js, but... I'm not super familiar with this codebase but I thought "accept" was intended to supercede "extension"?

An oversight in original patch didn't accommodate a comma at the END of the type param, only the beginning or middle.  This corrects that problem.
@rskm1
Copy link
ContributorAuthor

Here's an illustration of why those blank choices need to be handled separately by this code and NOT by RegExp. Basically, the RegExp library that javascript uses has a known bug in it.

Javascript console excerpt:

function m(p,t) { console.log(p.match(new RegExp( ".?(" + t + ")$", "i"))) }
m('gif', 'jpg|jpeg')
null
m('gif', 'jpg||jpeg')
["f", "", index: 2, input: "gif"]

As you can see, RegExp "finds" a match where there really ISN'T a match, just because of the double-| (or blank prefix | or blank suffix |) in there.

@staabm
Copy link
Member

I am fine with the change, only thing missing is a test.

@jzaefferer
Copy link
Collaborator

There are tests for theaccept method in#1373, which fixes another problem with the method.@rskm1 can I interest you in checkout out that PR and merging it with your changes?

@rskm1
Copy link
ContributorAuthor

Oh, very nice!#1373 looks good to me, but I'm not sure how to merge someone else's branch into my own using github's web interface. If you go ahead and merge#1373 into master, this PR will have merge conflicts that I'm pretty sure I can figure out how to clean up, and add more "accept" test cases to.

@jzaefferer
Copy link
Collaborator

Well, you can't run the tests from the GitHub web interface either (right?). Making a local clone and editing there shouldn't be a big barrier. Let me know if you need help with that.

@jzaefferer
Copy link
Collaborator

@rskm1 are you still interested in this? Your help is definitely very welcome.

@staabm
Copy link
Member

Closing, as its very old. if you still need this, please shout out.

@staabmstaabm closed thisOct 21, 2015
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@rskm1@jzaefferer@staabm

[8]ページ先頭

©2009-2025 Movatter.jp