From f5e09f843b76999a6d581a01bc53a8bb99caea99 Mon Sep 17 00:00:00 2001 From: ruanltbg Date: Mon, 6 Nov 2017 17:10:54 -0200 Subject: [PATCH] Change extension validation to be case insensitive --- bower.json | 4 ++-- package.json | 2 +- uploader.js | 5 ++--- uploader.min.js | 4 ++-- uploader/methods.js | 3 +-- uploader/uploader.js | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/bower.json b/bower.json index 814a393..c126f04 100755 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "UploaderJS", - "version": "0.9.0", + "version": "0.9.3", "main": "uploader.js", "ignore": [ "**/.*", @@ -9,4 +9,4 @@ "package.json", ".gitignore" ] -} \ No newline at end of file +} diff --git a/package.json b/package.json index a543406..9ec2ee6 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "UploaderJS", - "version": "0.9.0", + "version": "0.9.3", "description": "Cross browser file uploading made easy.", "main": "Gruntfile.js", "scripts": { diff --git a/uploader.js b/uploader.js index da9277b..71f4f45 100644 --- a/uploader.js +++ b/uploader.js @@ -1,5 +1,5 @@ /** - * UploaderJS v0.9.0 + * UploaderJS v0.9.3 * https://github.com/tamaspap/uploader * * Copyright 2014, Pap Tamas @@ -817,8 +817,7 @@ // Check if file type is accepted - if (allowedExtensions && $.inArray("." + fileExtension, allowedExtensions) < 0) { - + if (allowedExtensions && !new RegExp('\.'+ fileExtension, 'i').test(allowedExtensions.join())) { // Invalid file type errors.push({ code: 1, diff --git a/uploader.min.js b/uploader.min.js index 89e1c0e..994c4d9 100644 --- a/uploader.min.js +++ b/uploader.min.js @@ -1,2 +1,2 @@ -/*! UploaderJS 2016-11-04, 7:31:35 PM */ -!function(a,b){"use strict";function c(a){this.init(a)}a.extend(c,{defaults:{selectButton:null,dropZone:null,name:"file",multiple:!0,url:null,method:"POST",autoUpload:!0,removeOnFail:!0,headers:{},data:{},acceptType:null,acceptSize:[null,null],maxFiles:null,simultaneousUploads:3,degrade:!1,cssClasses:{dropZoneDragOver:"drop-zone-drag-over"},errors:{invalidType:"The file '{{fileName}}' is not valid. Please upload only files with the following extensions: {{allowedExtensions}}.",sizeTooSmall:"The file '{{fileName}}' is too small. Please upload only files bigger than {{allowedMinSize}}.",sizeTooLarge:"The file '{{fileName}}' is too large. Please upload only files smaller than {{allowedMaxSize}}.",tooManyFiles:"Can not upload the file '{{fileName}}'', because you can upload only {{maxFiles}} file(s).",networkError:"There was a problem uploading the file '{{fileName}}'. Please try uploading that file again."},uniqueIdPrefix:"upload_"},uniqueIncrement:1,support:function(a){var b={};b.xhrUpload=!!a.FormData&&!!a.XMLHttpRequest&&"upload"in new XMLHttpRequest,b.selectMultiple=!!a.FileList&&"multiple"in document.createElement("input");var c=document.createElement("div");return b.dropFiles="ondragstart"in c&&"ondrop"in c&&!!a.FileList,b}(b),STATUS_ADDED:"ADDED",STATUS_UPLOADING:"UPLOADING",STATUS_COMPLETED:"COMPLETED",STATUS_PENDING:"PENDING",STATUS_FAILED:"FAILED"}),b.Uploader=c}(jQuery,window),function(a,b){"use strict";b.extend(a.prototype,{init:function(a){this.options=b.extend(!0,{},this.constructor.defaults,a),this.isModernBrowser=this.constructor.support.xhrUpload&&!this.options.degrade,this.fileList={},this.pendingList=[],this.fileCount=0,this.eventHandlers={},this.initElements()},initElements:function(){this.$selectButton=b(this.options.selectButton),this.createFileInput(),this.options.dropZone&&this.constructor.support.dropFiles&&this.isModernBrowser&&this.initDropZone()},createFileInput:function(){this.$fileInput=b("",{name:this.options.name,accept:(this.options.acceptType||[]).join(),type:"file"}).appendTo(this.$selectButton),this.options.multiple&&this.constructor.support.selectMultiple&&this.isModernBrowser&&this.$fileInput.attr("multiple","multiple"),this.$fileInput.on("change",b.proxy(this.onFileSelect,this))},initDropZone:function(){this.$dropZone=b(this.options.dropZone),this.$dropZone.on("dragover.Uploader",b.proxy(function(a){return a.preventDefault(),this.$dropZone.addClass(this.options.cssClasses.dropZoneDragOver),!1},this)),this.$dropZone.on("dragend.Uploader",b.proxy(function(a){return a.preventDefault(),this.$dropZone.removeClass(this.options.cssClasses.dropZoneDragOver),!1},this)),this.$dropZone.on("dragleave.Uploader",b.proxy(function(a){return a.preventDefault(),this.$dropZone.removeClass(this.options.cssClasses.dropZoneDragOver),!1},this)),this.$dropZone.on("drop.Uploader",b.proxy(function(a){a.preventDefault(),this.$dropZone.removeClass(this.options.cssClasses.dropZoneDragOver),a.originalEvent.dataTransfer&&a.originalEvent.dataTransfer.files&&this.addToList(a.originalEvent.dataTransfer.files)},this))}})}(window.Uploader,jQuery),function(a,b){"use strict";b.extend(a.prototype,{onFileSelect:function(){var a=this.isModernBrowser?this.$fileInput[0].files:[this.$fileInput];this.addToList(a),this.isModernBrowser?this.$fileInput.remove():this.$fileInput.off().detach(),this.createFileInput()},onFileAdd:function(a,b,c){this.trigger("fileAdd",a,b,c)},onFileRemove:function(a,b){this.trigger("fileRemove",a,b)},onFileInvalid:function(a,b){this.trigger("fileInvalid",a,b)},onTooManyFiles:function(a,b){this.trigger("tooManyFiles",a,b)},onBeforeUpload:function(a,b,c,d){this.trigger("beforeUpload",a,b,c,d)},onUploadStart:function(a,b){var c=(new Date).getTime();this.fileList[a].progress={startTime:c,endTime:null,previous:{time:null,bytes:0},current:{time:c,bytes:0}},this.trigger("uploadStart",a,b)},onUploadProgress:function(a,b,c,d){var e=(new Date).getTime(),f=this.fileList[a].progress;f.previous={time:f.current.time,bytes:f.current.bytes},f.current={time:e,bytes:c},c==d&&(f.endTime=e),this.trigger("uploadProgress",a,b,c,d)},onUploadComplete:function(a,b,c,d,e){try{this.trigger("uploadComplete",a,b,c,d,e),this.fileList[a].status=this.constructor.STATUS_COMPLETED,this.isModernBrowser||this.iFrameCleanUp(a),this.uploadNext()}catch(f){if("UploadError"!=f.name)throw f;this.onUploadFail(a,b,this.errorMessage(f.message,this.fileList[a].file))}},onUploadFail:function(a,b,c){this.fileList[a].status=this.constructor.STATUS_FAILED,this.trigger("uploadFail",a,b,c),this.fileCount--,this.isModernBrowser||this.iFrameCleanUp(a),this.options.removeOnFail&&this.removeFromList(a),this.uploadNext()},onUploadAbort:function(a,b){this.trigger("uploadAbort",a,b),this.fileCount--,this.isModernBrowser||this.iFrameCleanUp(a),this.removeFromList(a),this.uploadNext()},on:function(a,b){return this.eventHandlers[a]=this.eventHandlers[a]||[],this.eventHandlers[a].push(b),this},off:function(a){a?delete this.eventHandlers[a]:this.eventHandlers={}},trigger:function(){var a,b=arguments[0];this.eventHandlers[b]=this.eventHandlers[b]||[];for(var c=0;ce&&c.push({code:2,message:this.errorMessage(this.options.errors.sizeTooSmall,a)}),b.isNumeric(i)&&e>i&&c.push({code:3,message:this.errorMessage(this.options.errors.sizeTooLarge,a)})),c.length)throw{name:"FileValidationError",message:"Invalid file.",errors:c};return!0},upload:function(a){if(!this.isUploading(a)){var b=this.countFiles(this.constructor.STATUS_UPLOADING);b-1&&this.pendingList.splice(c,1)},uploadNext:function(){this.pendingList.length>0&&this.upload(this.pendingList[0])},getBytes:function(a){if(!this.isModernBrowser)return null;if(a)return this.fileList[a].file.size;var b=0;for(var c in this.fileList)b+=this.fileList[c].file.size;return b},getUploadedBytes:function(a){if(!this.isModernBrowser)return null;if(a)return this.isUploading(a)?this.fileList[a].progress.current.bytes:0;var b=0;for(var c in this.fileList)b+=this.getUploadedBytes(c);return b},getUploadSpeed:function(a,b){if(!this.isModernBrowser)return null;if(b===d&&(b=!0),a){var c=this.fileList[a].progress;return c.current.bytes&&c.current.bytes!=this.getBytes(a)?b?Math.round(c.current.bytes/((c.current.time-c.startTime)/1e3)):Math.round((c.current.bytes-c.previous.bytes)/((c.current.time-c.previous.time)/1e3)):0}var e=0;for(var f in this.fileList)e+=this.getUploadSpeed(f,b);return e},getTimeLeft:function(a,b){if(!this.isModernBrowser)return null;if(a)return Math.max(Math.ceil((this.getBytes(a)-this.getUploadedBytes(a))/this.getUploadSpeed(a,b)),1);var c=0;for(var d in this.fileList)c=Math.max(c,this.getTimeLeft(d,b));return c},destroy:function(){delete this.eventHandlers,this.$dropZone&&this.$dropZone.off(".Uploader");for(var a in this.fileList)this.fileList[a].status==this.constructor.STATUS_UPLOADING&&(this.isModernBrowser&&this.removeXHREventHandlers(a),this.abort(a));delete this.fileList,delete this.pendingList,this.$fileInput.remove()},ajaxUpload:function(a){var c,d=new XMLHttpRequest;this.attachXHREventHandlers(d,a),this.fileList[a].request=d;var e=b.extend({},this.options.data);this.onBeforeUpload(a,this.fileList[a].name,e,d);var f=new FormData;for(c in e)f.append(c,e[c]);f.append(this.options.name,this.fileList[a].file),d.open(this.options.method,this.options.url,!0),d.setRequestHeader("X-Requested-With","XMLHttpRequest");for(c in this.options.headers)d.setRequestHeader(c,this.options.headers[c]);d.send(f)},ajaxAbort:function(a){this.isUploading(a)&&this.fileList[a].request.abort()},attachXHREventHandlers:function(a,c){var d=this.fileList[c].name,e={load:b.proxy(function(a){this.onUploadComplete(c,d,a.target.responseText,a.target.status,a.target)},this),error:b.proxy(function(){var a=this.errorMessage(this.options.errors.networkError,this.fileList[c].file);this.onUploadFail(c,d,a)},this),abort:b.proxy(function(){this.onUploadAbort(c,d)},this),progress:b.proxy(function(a){this.onUploadProgress(c,d,a.loaded,a.total)},this)};a.addEventListener("load",e.load,!1),a.addEventListener("error",e.error,!1),a.addEventListener("abort",e.abort,!1),a.upload.addEventListener("progress",e.progress,!1),a.eventHandlers=e},removeXHREventHandlers:function(a){if(this.isUploading(a)){var b=this.fileList[a].request,c=b.eventHandlers;b.removeEventListener("load",c.load),b.removeEventListener("error",c.error),b.removeEventListener("abort",c.abort),b.upload.removeEventListener("progress",c.progress),delete b.eventHandlers}},iFrameUpload:function(a){var c=this.createForm(a),d=this.createIFrame(a);c.attr("target",d.attr("id"));var e=b.extend({},this.options.data);this.onBeforeUpload(a,this.fileList[a].name,e,null);for(var f in e)b("",{type:"hidden",name:f,value:e[f]}).appendTo(c);this.fileList[a].file.appendTo(c),c.submit(),this.fileList[a].request=d},iFrameAbort:function(a){this.isUploading(a)&&(c.navigator.userAgent.indexOf("MSIE")>-1?this.fileList[a].request[0].contentWindow.document.execCommand("Stop"):this.fileList[a].request[0].contentWindow.stop(),b("#"+a+"_iframe").off(),this.onUploadAbort(a,this.fileList[a].name))},createForm:function(a){return b("
",{enctype:"multipart/form-data",method:this.options.method,action:this.options.url,id:a+"_form"}).css({display:"none"}).appendTo(document.body)},createIFrame:function(a){var c=b("