Skip to content

Commit d629e0e

Browse files
Adam HopkinsAdam Hopkins
authored andcommitted
Added reject_file_types
1 parent 6ee9702 commit d629e0e

File tree

9 files changed

+112
-22
lines changed

9 files changed

+112
-22
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,6 @@ Revision history for jQuery-File-Upload
111111

112112
0.28
113113
Fixed "user_eror" typo for delete in handle_request
114+
115+
0.29
116+
Added reject_file_types

MYMETA.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@
4646
}
4747
},
4848
"release_status" : "stable",
49-
"version" : "0.28"
49+
"version" : "0.29"
5050
}

MYMETA.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ requires:
2828
Net::SSH2::SFTP: '0'
2929
URI: '0'
3030
perl: '5.006'
31-
version: '0.28'
31+
version: '0.29'

Makefile

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ DIRFILESEP = /
6262
DFSEP = $(DIRFILESEP)
6363
NAME = jQuery::File::Upload
6464
NAME_SYM = jQuery_File_Upload
65-
VERSION = 0.28
65+
VERSION = 0.29
6666
VERSION_MACRO = VERSION
67-
VERSION_SYM = 0_28
67+
VERSION_SYM = 0_29
6868
DEFINE_VERSION = -D$(VERSION_MACRO)=\"$(VERSION)\"
69-
XS_VERSION = 0.28
69+
XS_VERSION = 0.29
7070
XS_VERSION_MACRO = XS_VERSION
7171
XS_DEFINE_VERSION = -D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"
7272
INST_ARCHLIB = blib/arch
@@ -187,15 +187,12 @@ PERL_ARCHIVE_AFTER =
187187

188188

189189
TO_INST_PM = lib/jQuery/File/.DS_Store \
190-
lib/jQuery/File/Upload.pm \
191-
num.pl
190+
lib/jQuery/File/Upload.pm
192191

193192
PM_TO_BLIB = lib/jQuery/File/.DS_Store \
194193
blib/lib/jQuery/File/.DS_Store \
195194
lib/jQuery/File/Upload.pm \
196-
blib/lib/jQuery/File/Upload.pm \
197-
num.pl \
198-
$(INST_LIB)/jQuery/File/num.pl
195+
blib/lib/jQuery/File/Upload.pm
199196

200197

201198
# --- MakeMaker platform_constants section:
@@ -265,7 +262,7 @@ RCS_LABEL = rcs -Nv$(VERSION_SYM): -q
265262
DIST_CP = best
266263
DIST_DEFAULT = tardist
267264
DISTNAME = jQuery-File-Upload
268-
DISTVNAME = jQuery-File-Upload-0.28
265+
DISTVNAME = jQuery-File-Upload-0.29
269266

270267

271268
# --- MakeMaker macro section:
@@ -517,7 +514,7 @@ metafile : create_distdir
517514
$(NOECHO) $(ECHO) ' Net::SSH2::SFTP: '\''0'\''' >> META_new.yml
518515
$(NOECHO) $(ECHO) ' URI: '\''0'\''' >> META_new.yml
519516
$(NOECHO) $(ECHO) ' perl: '\''5.006'\''' >> META_new.yml
520-
$(NOECHO) $(ECHO) 'version: '\''0.28'\''' >> META_new.yml
517+
$(NOECHO) $(ECHO) 'version: '\''0.29'\''' >> META_new.yml
521518
-$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml
522519
$(NOECHO) $(ECHO) Generating META.json
523520
$(NOECHO) $(ECHO) '{' > META_new.json
@@ -568,7 +565,7 @@ metafile : create_distdir
568565
$(NOECHO) $(ECHO) ' }' >> META_new.json
569566
$(NOECHO) $(ECHO) ' },' >> META_new.json
570567
$(NOECHO) $(ECHO) ' "release_status" : "stable",' >> META_new.json
571-
$(NOECHO) $(ECHO) ' "version" : "0.28"' >> META_new.json
568+
$(NOECHO) $(ECHO) ' "version" : "0.29"' >> META_new.json
572569
$(NOECHO) $(ECHO) '}' >> META_new.json
573570
-$(NOECHO) $(MV) META_new.json $(DISTVNAME)/META.json
574571

@@ -894,8 +891,7 @@ ppd :
894891
pm_to_blib : $(FIRST_MAKEFILE) $(TO_INST_PM)
895892
$(NOECHO) $(ABSPERLRUN) -MExtUtils::Install -e 'pm_to_blib({@ARGV}, '\''$(INST_LIB)/auto'\'', q[$(PM_FILTER)], '\''$(PERM_DIR)'\'')' -- \
896893
lib/jQuery/File/.DS_Store blib/lib/jQuery/File/.DS_Store \
897-
lib/jQuery/File/Upload.pm blib/lib/jQuery/File/Upload.pm \
898-
num.pl $(INST_LIB)/jQuery/File/num.pl
894+
lib/jQuery/File/Upload.pm blib/lib/jQuery/File/Upload.pm
899895
$(NOECHO) $(TOUCH) pm_to_blib
900896

901897

blib/lib/jQuery/File/Upload.pm

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ use Data::GUID;
1717
#use LWP::UserAgent;
1818
#use LWP::Protocol::https;
1919

20-
our $VERSION = '0.28';
20+
our $VERSION = '0.29';
2121

2222
my %errors = (
2323
'_validate_max_file_size' => 'File is too big',
2424
'_validate_min_file_size' => 'File is too small',
2525
'_validate_accept_file_types' => 'Filetype not allowed',
26+
'_validate_reject_file_types' => 'Filetype not allowed',
2627
'_validate_max_number_of_files' => 'Maximum number of files exceeded',
2728
'_validate_max_width' => 'Image exceeds maximum width',
2829
'_validate_min_width' => 'Image requires a minimum width',
@@ -91,6 +92,7 @@ sub new {
9192
max_file_size => undef,
9293
min_file_size => 1,
9394
accept_file_types => [],
95+
reject_file_types => [],
9496
require_image => undef,
9597
max_width => undef,
9698
max_height => undef,
@@ -305,8 +307,8 @@ sub accept_file_types {
305307
my $self = shift;
306308

307309
if (@_) {
308-
my $a_ref = shift;
309-
die "accept_file_types must be an array ref" unless UNIVERSAL::isa($a_ref,'ARRAY');
310+
my $a_ref = shift;
311+
die "accept_file_types must be an array ref" unless UNIVERSAL::isa($a_ref,'ARRAY');
310312
$self->{accept_file_types} = $a_ref;
311313
}
312314

@@ -317,6 +319,18 @@ sub accept_file_types {
317319
return $self->{accept_file_types};
318320
}
319321

322+
sub reject_file_types {
323+
my $self = shift;
324+
325+
if (@_) {
326+
my $a_ref = shift;
327+
die "reject_file_types must be an array ref" unless UNIVERSAL::isa($a_ref,'ARRAY');
328+
$self->{reject_file_types} = $a_ref;
329+
}
330+
331+
return $self->{reject_file_types};
332+
}
333+
320334
sub require_image {
321335
my $self = shift;
322336

@@ -1051,6 +1065,7 @@ sub _validate_file {
10511065
$self->_validate_max_file_size and
10521066
$self->_validate_min_file_size and
10531067
$self->_validate_accept_file_types and
1068+
$self->_validate_reject_file_types and
10541069
$self->_validate_max_width and
10551070
$self->_validate_min_width and
10561071
$self->_validate_max_height and
@@ -1197,6 +1212,23 @@ sub _validate_accept_file_types {
11971212
}
11981213
}
11991214

1215+
sub _validate_reject_file_types {
1216+
my $self = shift;
1217+
1218+
#if reject_file_types is empty, we except all types
1219+
#so return true
1220+
return 1 unless @{$self->reject_file_types};
1221+
1222+
unless(grep { $_ eq $self->{file_type} } @{$self->{reject_file_types}}) {
1223+
return 1;
1224+
}
1225+
else {
1226+
my $types = join ",", @{$self->reject_file_types};
1227+
$self->{error} = ['_validate_reject_file_types',[$types],$self->{file_type}];
1228+
return undef;
1229+
}
1230+
}
1231+
12001232
sub _validate_max_width {
12011233
my $self = shift;
12021234
return 1 unless $self->is_image;
@@ -2098,6 +2130,14 @@ Sets the minimum file size in bytes. Default minimum is 1 byte. to disable a min
20982130
Sets what file types are allowed to be uploaded. By default, all file types are allowed.
20992131
File types should be in the format of the Content-Type header sent on requests.
21002132
2133+
=head3 reject_file_types
2134+
2135+
#None of these types are allowed.
2136+
$j_fu->reject_file_types(['image/jpeg','image/png','image/gif','text/html']);
2137+
2138+
Sets what file types are NOT allowed to be uploaded. By default, all file types are allowed.
2139+
File types should be in the format of the Content-Type header sent on requests.
2140+
21012141
=head3 require_image
21022142
21032143
$j_fu->require_image(1);

blib/man3/jQuery::File::Upload.3pm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
.\" ========================================================================
125125
.\"
126126
.IX Title "jQuery::File::Upload 3"
127-
.TH jQuery::File::Upload 3 "2014-07-15" "perl v5.16.2" "User Contributed Perl Documentation"
127+
.TH jQuery::File::Upload 3 "2014-07-20" "perl v5.16.2" "User Contributed Perl Documentation"
128128
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
129129
.\" way too many mistakes in technical documents.
130130
.if n .ad l
@@ -591,6 +591,17 @@ Sets the minimum file size in bytes. Default minimum is 1 byte. to disable a min
591591
Sets what file types are allowed to be uploaded. By default, all file types are allowed.
592592
File types should be in the format of the Content-Type header sent on requests.
593593
.PP
594+
\fIreject_file_types\fR
595+
.IX Subsection "reject_file_types"
596+
.PP
597+
.Vb 2
598+
\& #None of these types are allowed.
599+
\& $j_fu\->reject_file_types([\*(Aqimage/jpeg\*(Aq,\*(Aqimage/png\*(Aq,\*(Aqimage/gif\*(Aq,\*(Aqtext/html\*(Aq]);
600+
.Ve
601+
.PP
602+
Sets what file types are \s-1NOT\s0 allowed to be uploaded. By default, all file types are allowed.
603+
File types should be in the format of the Content-Type header sent on requests.
604+
.PP
594605
\fIrequire_image\fR
595606
.IX Subsection "require_image"
596607
.PP

jQuery-File-Upload-0.28.tar.gz

-20.4 KB
Binary file not shown.

jQuery-File-Upload-0.29.tar.gz

20.5 KB
Binary file not shown.

lib/jQuery/File/Upload.pm

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ use Data::GUID;
1717
#use LWP::UserAgent;
1818
#use LWP::Protocol::https;
1919

20-
our $VERSION = '0.28';
20+
our $VERSION = '0.29';
2121

2222
my %errors = (
2323
'_validate_max_file_size' => 'File is too big',
2424
'_validate_min_file_size' => 'File is too small',
2525
'_validate_accept_file_types' => 'Filetype not allowed',
26+
'_validate_reject_file_types' => 'Filetype not allowed',
2627
'_validate_max_number_of_files' => 'Maximum number of files exceeded',
2728
'_validate_max_width' => 'Image exceeds maximum width',
2829
'_validate_min_width' => 'Image requires a minimum width',
@@ -91,6 +92,7 @@ sub new {
9192
max_file_size => undef,
9293
min_file_size => 1,
9394
accept_file_types => [],
95+
reject_file_types => [],
9496
require_image => undef,
9597
max_width => undef,
9698
max_height => undef,
@@ -305,8 +307,8 @@ sub accept_file_types {
305307
my $self = shift;
306308

307309
if (@_) {
308-
my $a_ref = shift;
309-
die "accept_file_types must be an array ref" unless UNIVERSAL::isa($a_ref,'ARRAY');
310+
my $a_ref = shift;
311+
die "accept_file_types must be an array ref" unless UNIVERSAL::isa($a_ref,'ARRAY');
310312
$self->{accept_file_types} = $a_ref;
311313
}
312314

@@ -317,6 +319,18 @@ sub accept_file_types {
317319
return $self->{accept_file_types};
318320
}
319321

322+
sub reject_file_types {
323+
my $self = shift;
324+
325+
if (@_) {
326+
my $a_ref = shift;
327+
die "reject_file_types must be an array ref" unless UNIVERSAL::isa($a_ref,'ARRAY');
328+
$self->{reject_file_types} = $a_ref;
329+
}
330+
331+
return $self->{reject_file_types};
332+
}
333+
320334
sub require_image {
321335
my $self = shift;
322336

@@ -1051,6 +1065,7 @@ sub _validate_file {
10511065
$self->_validate_max_file_size and
10521066
$self->_validate_min_file_size and
10531067
$self->_validate_accept_file_types and
1068+
$self->_validate_reject_file_types and
10541069
$self->_validate_max_width and
10551070
$self->_validate_min_width and
10561071
$self->_validate_max_height and
@@ -1197,6 +1212,23 @@ sub _validate_accept_file_types {
11971212
}
11981213
}
11991214

1215+
sub _validate_reject_file_types {
1216+
my $self = shift;
1217+
1218+
#if reject_file_types is empty, we except all types
1219+
#so return true
1220+
return 1 unless @{$self->reject_file_types};
1221+
1222+
unless(grep { $_ eq $self->{file_type} } @{$self->{reject_file_types}}) {
1223+
return 1;
1224+
}
1225+
else {
1226+
my $types = join ",", @{$self->reject_file_types};
1227+
$self->{error} = ['_validate_reject_file_types',[$types],$self->{file_type}];
1228+
return undef;
1229+
}
1230+
}
1231+
12001232
sub _validate_max_width {
12011233
my $self = shift;
12021234
return 1 unless $self->is_image;
@@ -2098,6 +2130,14 @@ Sets the minimum file size in bytes. Default minimum is 1 byte. to disable a min
20982130
Sets what file types are allowed to be uploaded. By default, all file types are allowed.
20992131
File types should be in the format of the Content-Type header sent on requests.
21002132
2133+
=head3 reject_file_types
2134+
2135+
#None of these types are allowed.
2136+
$j_fu->reject_file_types(['image/jpeg','image/png','image/gif','text/html']);
2137+
2138+
Sets what file types are NOT allowed to be uploaded. By default, all file types are allowed.
2139+
File types should be in the format of the Content-Type header sent on requests.
2140+
21012141
=head3 require_image
21022142
21032143
$j_fu->require_image(1);

0 commit comments

Comments
 (0)