Skip to content

Commit

Permalink
Ignore case of file extension in suffixIn()
Browse files Browse the repository at this point in the history
  • Loading branch information
capasky committed Aug 18, 2016
1 parent c0b66e9 commit 25f0714
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/file.EXT
@@ -0,0 +1 @@
file
2 changes: 2 additions & 0 deletions test/test_checkFile.js
Expand Up @@ -15,6 +15,7 @@ describe('koa-validate' , function(){
this.checkFile('empty').empty();
// this.checkFile('file1').empty().contentTypeMatch(/^text/);
this.checkFile('file').empty().contentTypeMatch(/^application\//);
this.checkFile('file3').notEmpty().suffixIn(['ext']);
yield this.checkFile('file1').empty().move(__dirname+"/temp", function(file , context){
});
this.checkFile('file').notEmpty();
Expand All @@ -41,6 +42,7 @@ describe('koa-validate' , function(){
.attach('file',__dirname+"/test_checkFile.js")
.attach('file1',__dirname+"/test_checkFile.js")
// .attach('file2',__dirname+"/test_checkFile.js")
.attach('file3',__dirname+"/file.EXT")
.send({type:"js"})
.expect(200)
.expect('ok' , done);
Expand Down
3 changes: 2 additions & 1 deletion validate.js
Expand Up @@ -862,7 +862,8 @@ FileValidator.prototype.fileNameMatch = function(reg,tip){
return this;
};
FileValidator.prototype.suffixIn = function(arr,tip){
if (this.goOn && (!this.value || -1==arr.indexOf(-1==this.value.name.lastIndexOf('.')?"":this.value.name.substring(this.value.name.lastIndexOf('.')+1)))) {
arr = arr.map(function(ext) { return (ext + '').toLowerCase(); });
if (this.goOn && (!this.value || -1==arr.indexOf(-1==this.value.name.lastIndexOf('.')?"":this.value.name.substring(this.value.name.lastIndexOf('.')+1).toLowerCase()))) {
this.addError(tip || "file "+ (this.value && this.value.name||this.key) + " is bad file type.");
if(this.deleteOnCheckFailed){
delFileAsync(this.value &&this.value.path);
Expand Down

0 comments on commit 25f0714

Please sign in to comment.