mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-20 09:11:40 +01:00
Core: Extract the file name without including "C:\fakepath\"
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 #1615
This commit is contained in:
31
src/core.js
31
src/core.js
@@ -624,9 +624,9 @@ $.extend( $.validator, {
|
||||
},
|
||||
|
||||
elementValue: function( element ) {
|
||||
var val,
|
||||
$element = $( element ),
|
||||
type = element.type;
|
||||
var $element = $( element ),
|
||||
type = element.type,
|
||||
val, idx;
|
||||
|
||||
if ( type === "radio" || type === "checkbox" ) {
|
||||
return this.findByName( element.name ).filter( ":checked" ).val();
|
||||
@@ -639,6 +639,31 @@ $.extend( $.validator, {
|
||||
} else {
|
||||
val = $element.val();
|
||||
}
|
||||
|
||||
if ( type === "file" ) {
|
||||
|
||||
// Modern browser (chrome & safari)
|
||||
if ( val.substr( 0, 12 ) === "C:\\fakepath\\" ) {
|
||||
return val.substr( 12 );
|
||||
}
|
||||
|
||||
// Legacy browsers
|
||||
// Unix-based path
|
||||
idx = val.lastIndexOf( "/" );
|
||||
if ( idx >= 0 ) {
|
||||
return val.substr( idx + 1 );
|
||||
}
|
||||
|
||||
// Windows-based path
|
||||
idx = val.lastIndexOf( "\\" );
|
||||
if ( idx >= 0 ) {
|
||||
return val.substr( idx + 1 );
|
||||
}
|
||||
|
||||
// Just the file name
|
||||
return val;
|
||||
}
|
||||
|
||||
if ( typeof val === "string" ) {
|
||||
return val.replace( /\r/g, "" );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user