Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ( this.type === 'file' ) {
file = this.files[ 0 ]; // Why doesn't this fail for empty file inputs?
} else if ( this.value ) {
canvas = $( this ).closest( '.question' )[ 0 ].querySelector( '.draw-widget canvas' );
if ( canvas && !URL_RE.test( this.value ) ) {
// TODO: In the future, we could do canvas.toBlob()
file = utils.dataUriToBlobSync( canvas.toDataURL() );
file.name = this.value;
}
}
if ( file && file.name ) {
// Correct file names by adding a unique-ish postfix
// First create a clone, because the name property is immutable
// TODO: in the future, when browser support increase we can invoke
// the File constructor to do this.
newFilename = getFilename( file, this.dataset.filenamePostfix );
// If file is resized, get Blob representation of data URI
if ( this.dataset.resized && this.dataset.resizedDataURI ) {
file = utils.dataUriToBlobSync( this.dataset.resizedDataURI );
}
file = new Blob( [ file ], {
type: file.type
} );
file.name = newFilename;
files.push( file );
}
} );