Skip to content
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

Use greedy regexes #556

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions resumable.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
}
var relativePath = file.webkitRelativePath||file.relativePath||file.fileName||file.name; // Some confusion in different versions of Firefox
var size = file.size;
return(size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, ''));
return(size + '-' + relativePath.replace(/[^\w-]+/g, ''));
},
contains:function(array,test) {
var result = false;
Expand Down Expand Up @@ -367,7 +367,7 @@
}
}
);
};
}

var appendFilesFromFileList = function(fileList, event){
// check for uploading too many files
Expand All @@ -383,7 +383,7 @@
}
}
var files = [], filesSkipped = [], remaining = fileList.length;
var decreaseReamining = function(){
var decreaseRemaining = function(){
if(!--remaining){
// all files processed, trigger event
if(!files.length && !filesSkipped.length){
Expand All @@ -402,7 +402,7 @@
var fileTypeFound = false;
for(var index in o.fileType){
// For good behaviour we do some inital sanitizing. Remove spaces and lowercase all
o.fileType[index] = o.fileType[index].replace(/\s/g, '').toLowerCase();
o.fileType[index] = o.fileType[index].replace(/\s+/g, '').toLowerCase();

// Allowing for both [extension, .extension, mime/type, mime/*]
var extension = ((o.fileType[index].match(/^[^.][^/]+$/)) ? '.' : '') + o.fileType[index];
Expand Down Expand Up @@ -446,7 +446,7 @@
})()} else {
filesSkipped.push(file);
};
decreaseReamining();
decreaseRemaining();
}
// directories have size == 0
var uniqueIdentifier = $h.generateUniqueIdentifier(file, event);
Expand All @@ -461,7 +461,7 @@
function(){
// unique identifier generation failed
// skip further processing, only decrease file count
decreaseReamining();
decreaseRemaining();
}
);
}else{
Expand Down Expand Up @@ -521,7 +521,7 @@
// Stop current uploads
var abortCount = 0;
$h.each($.chunks, function(c){
if(c.status()=='uploading') {
if(c.status()==='uploading') {
c.abort();
abortCount++;
}
Expand All @@ -534,7 +534,7 @@
$.chunks = [];
// Stop current uploads
$h.each(_chunks, function(c){
if(c.status()=='uploading') {
if(c.status()==='uploading') {
c.abort();
$.resumableObj.uploadNextChunk();
}
Expand Down Expand Up @@ -574,7 +574,7 @@
var ret = 0;
var error = false;
$h.each($.chunks, function(c){
if(c.status()=='error') error = true;
if(c.status()==='error') error = true;
ret += c.progress(true); // get chunk progress relative to entire file
});
ret = (error ? 1 : (ret>0.99999 ? 1 : ret));
Expand All @@ -585,7 +585,7 @@
$.isUploading = function(){
var uploading = false;
$h.each($.chunks, function(chunk){
if(chunk.status()=='uploading') {
if(chunk.status()==='uploading') {
uploading = true;
return(false);
}
Expand All @@ -599,7 +599,7 @@
}
$h.each($.chunks, function(chunk){
var status = chunk.status();
if(status=='pending' || status=='uploading' || chunk.preprocessState === 1) {
if(status==='pending' || status==='uploading' || chunk.preprocessState === 1) {
outstanding = true;
return(false);
}
Expand Down Expand Up @@ -632,15 +632,15 @@
}
}
$h.each($.chunks, function (chunk) {
if (chunk.status() == 'pending' && chunk.preprocessState !== 1) {
if (chunk.status() === 'pending' && chunk.preprocessState !== 1) {
chunk.send();
found = true;
return(false);
}
});
}
return(found);
}
};
$.markChunksCompleted = function (chunkNumber) {
if (!$.chunks || $.chunks.length <= chunkNumber) {
return;
Expand Down Expand Up @@ -693,7 +693,7 @@
var testHandler = function(e){
$.tested = true;
var status = $.status();
if(status=='success') {
if(status==='success') {
$.callback(status, $.message());
$.resumableObj.uploadNextChunk();
} else {
Expand Down Expand Up @@ -791,7 +791,7 @@
// Done (either done, failed or retry)
var doneHandler = function(e){
var status = $.status();
if(status=='success'||status=='error') {
if(status==='success'||status==='error') {
$.callback(status, $.message());
$.resumableObj.uploadNextChunk();
} else {
Expand Down Expand Up @@ -891,7 +891,7 @@
});

if ($.getOpt('chunkFormat') == 'blob') {
$.xhr.send(data);
$.xhr.send(data);
}
};
$.abort = function(){
Expand All @@ -906,14 +906,14 @@
// there might just be a slight delay before the retry starts
return('uploading');
} else if($.markComplete) {
return 'success';
return('success');
} else if(!$.xhr) {
return('pending');
} else if($.xhr.readyState<4) {
// Status is really 'OPENED', 'HEADERS_RECEIVED' or 'LOADING' - meaning that stuff is happening
return('uploading');
} else {
if($.xhr.status == 200 || $.xhr.status == 201) {
if($.xhr.status === 200 || $.xhr.status === 201) {
// HTTP 200, 201 (created)
return('success');
} else if($h.contains($.getOpt('permanentErrors'), $.xhr.status) || $.retries >= $.getOpt('maxChunkRetries')) {
Expand Down Expand Up @@ -958,12 +958,12 @@
// metadata and determine if there's even a point in continuing.
if ($.getOpt('prioritizeFirstAndLastChunk')) {
$h.each($.files, function(file){
if(file.chunks.length && file.chunks[0].status()=='pending' && file.chunks[0].preprocessState === 0) {
if(file.chunks.length && file.chunks[0].status()==='pending' && file.chunks[0].preprocessState === 0) {
file.chunks[0].send();
found = true;
return(false);
}
if(file.chunks.length>1 && file.chunks[file.chunks.length-1].status()=='pending' && file.chunks[file.chunks.length-1].preprocessState === 0) {
if(file.chunks.length>1 && file.chunks[file.chunks.length-1].status()==='pending' && file.chunks[file.chunks.length-1].preprocessState === 0) {
file.chunks[file.chunks.length-1].send();
found = true;
return(false);
Expand Down Expand Up @@ -1029,7 +1029,7 @@
var fileTypes = $.getOpt('fileType');
if (typeof (fileTypes) !== 'undefined' && fileTypes.length >= 1) {
input.setAttribute('accept', fileTypes.map(function (e) {
e = e.replace(/\s/g, '').toLowerCase();
e = e.replace(/\s+/g, '').toLowerCase();
if(e.match(/^[^.][^/]+$/)){
e = '.' + e;
}
Expand Down