Skip to content

Commit 381c1ff

Browse files
committed
do not require provided sourcecode to be in base64
1 parent 3799b11 commit 381c1ff

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/RenderApp/Controller/Render.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ sub fetchRemoteSource_p {
9191
then(
9292
sub {
9393
my $tx = shift;
94-
return encode_base64($tx->result->body);
94+
return $tx->result->body;
9595
})->
9696
catch(
9797
sub {

lib/RenderApp/Model/Problem.pm

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use Mojo::IOLoop;
88
use Mojo::JSON qw( encode_json );
99
use Mojo::Base -async_await;
1010
use Time::HiRes qw( time );
11+
use MIME::Base64 qw( decode_base64 );
1112
use RenderApp::Controller::RenderProblem;
1213

1314
##### Problem params: #####
@@ -88,9 +89,12 @@ sub source {
8889
if ( scalar(@_) == 1 ) {
8990
my $contents = shift;
9091

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+
9196
# 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;
9498
$self->{problem_contents} = $contents;
9599
}
96100
return $self->{problem_contents};
@@ -131,7 +135,8 @@ sub path {
131135
}
132136
$self->{_error} = "404 I cannot find a problem with that file path."
133137
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;
135140
}
136141
return $self->{read_path};
137142
}

0 commit comments

Comments
 (0)