@@ -8,6 +8,7 @@ use Mojo::IOLoop;
8
8
use Mojo::JSON qw( encode_json ) ;
9
9
use Mojo::Base -async_await;
10
10
use Time::HiRes qw( time ) ;
11
+ use MIME::Base64 qw( decode_base64 ) ;
11
12
use RenderApp::Controller::RenderProblem;
12
13
13
14
# #### Problem params: #####
@@ -88,9 +89,12 @@ sub source {
88
89
if ( scalar (@_ ) == 1 ) {
89
90
my $contents = shift ;
90
91
92
+ # recognize and decode base64 if necessary
93
+ $contents = Encode::decode( " UTF-8" , decode_base64($contents ) )
94
+ if ( $contents =~ m ! ^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$ ! );
95
+
91
96
# UNIX style line-endings are required
92
- $contents =~ s /\r\n / \n / g ;
93
- $contents =~ s /\r / \n / g ;
97
+ $contents =~ s !\r\n ?! \n ! g ;
94
98
$self -> {problem_contents } = $contents ;
95
99
}
96
100
return $self -> {problem_contents };
@@ -131,7 +135,8 @@ sub path {
131
135
}
132
136
$self -> {_error } = " 404 I cannot find a problem with that file path."
133
137
unless ( -e $read_path || $force );
134
- $self -> {read_path } = Mojo::File-> new($read_path );
138
+ # if we objectify an empty string, it becomes truth-y -- AVOID!
139
+ $self -> {read_path } = Mojo::File-> new($read_path ) if $read_path ;
135
140
}
136
141
return $self -> {read_path };
137
142
}
0 commit comments