Skip to content

Core: Extract the file name without including "C:\fakepath\" #1651

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

Merged
merged 1 commit into from
Nov 24, 2015

Conversation

Arkni
Copy link
Member

@Arkni Arkni commented Nov 16, 2015

For historical reasons, the value IDL attribute prefixes the file name
with the string "C:\fakepath". As a result of this, this fix will extract
the file name from the value IDL attribute in a backwards-compatible way.

For more details, see:

Fixes #1615

@Arkni
Copy link
Member Author

Arkni commented Nov 18, 2015

Just remembered this and wondering why this should be added to the plugin if we have a transformer option that we can use for that.

JUST WONDERING

  • What someone can do with the name of a file ?
  • Why they want to validate its length ?

Finally, I think this PR should remain open until someone else claim about that.

@staabm what do you think ?

@staabm
Copy link
Member

staabm commented Nov 18, 2015

With this change we only cut the C:\fakepath\ prefix but leave the file-path and file-name as sent via the browser, right?

A user might validate the input file-name/path because of certain length restrictions in the db (e.g. VARCHAR(255)).
He might also check the filename for certain specialchars, which the backend does not support (e.g. utf8 chars in filenames).

Also as described in #1615 the maxlength and minlength options do not work correctly because of the magic-prefix.

@Arkni
Copy link
Member Author

Arkni commented Nov 18, 2015

With this change we only cut the C:\fakepath\ prefix but leave the file-path and file-name as sent via the browser, right?

The browser will send the file name prefixed by C:\fakepath\, so yes it only cuts that part and return the file name (as shown in unit test).

A user might validate the input file-name/path because of certain length restrictions in the db (e.g. VARCHAR(255)).
He might also check the filename for certain specialchars, which the backend does not support (e.g. utf8 chars in filenames).

Make sense. Thanks for the explanation :)

I've handled that in one of my project by generating a new name for the file (so the original name doesn't matter anymore, and sometimes using the title as name) and rely on the title that the user should enter.

Also as described in #1615 the maxlength and minlength options do not work correctly because of the magic-prefix.

Yes, so the PR still valid :D

@staabm
Copy link
Member

staabm commented Nov 18, 2015

@Arkni what do you think about adding a test for min or max length check for a file input?

@Arkni
Copy link
Member Author

Arkni commented Nov 18, 2015

@Arkni what do you think about adding a test for min or max length check for a file input?

Make sense as the issue we are trying to solve was about that.
I will try to work on it and see what can be done.

@Arkni
Copy link
Member Author

Arkni commented Nov 19, 2015

@staabm please double check.

If you have a better way to do the test, please let me know.

fileInput.value = "C:\\fakepath\\fakefile.txt";
ok( !v.check( fileInput ), "The fake file input is invalid (length = 12, maxlength = 10)" );

$.fn.rules = oldRules;
Copy link
Member

Choose a reason for hiding this comment

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

why resetting to oldRules and oldvalidationTargetFor?

Copy link
Member Author

Choose a reason for hiding this comment

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

in order to not affect other tests, I guess :)

Copy link
Member

Choose a reason for hiding this comment

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

@Arkni each test should live in its sandbox and the testframework is responsible for this kind of cleanup (I am not sure though qunit supports my assumption) ;)

Copy link
Member

Choose a reason for hiding this comment

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

I dont remember other unit tests doing such cleanup, so I am pretty sure we would have a lot of problems in case qunit would not already clean those things up (or boots a fresh environment for each test)

Copy link
Member Author

Choose a reason for hiding this comment

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

I dont remember other unit tests doing such cleanup, so I am pretty sure we would have a lot of problems in case qunit would not already clean those things up (or boots a fresh environment for each test)

I don't see such thing in their documentation (If I didn't miss something).
I guess we should ask someone from the core team for an answer, I don't know if jzaefferer has the time to do so.

Copy link
Member Author

Choose a reason for hiding this comment

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

But we should always play it safe ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, get ride of monkey patch rules() and used public api for validation :)

@Arkni Arkni force-pushed the issue-1615 branch 2 times, most recently from 6a6c245 to 9054789 Compare November 19, 2015 14:43
For historical reasons, the value IDL attribute prefixes the file name
with the string "C:\fakepath\". As a result of this,
this fix will extract the file name from the value IDL attribute in a
backwards-compatible way.

For more details, see:
 - http://www.w3.org/TR/html5/forms.html#dom-input-value-filename
 - http://www.w3.org/TR/html5/forms.html#fakepath-srsly

Fixes jquery-validation#1615
@staabm staabm merged commit a336e14 into jquery-validation:master Nov 24, 2015
@Arkni Arkni deleted the issue-1615 branch November 24, 2015 12:27
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.

C:\fakepath\ is added to length when checking the length of a file type
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy