|
@@ -52,7 +52,7 @@ get '/fortunes/?db' => sub {
|
|
|
$sth[1]->execute();
|
|
|
@objects = @{ $sth[1]->fetchall_arrayref( {} ) };
|
|
|
}
|
|
|
- push @objects, { message => "Additional fortune added at request time." };
|
|
|
+ push @objects, { id => 0, message => "Additional fortune added at request time." };
|
|
|
fortunes( \@objects );
|
|
|
};
|
|
|
|
|
@@ -86,7 +86,8 @@ run;
|
|
|
sub query {
|
|
|
my ( $db, $count ) = @_;
|
|
|
$count //= 1;
|
|
|
- $count = 1 unless $count =~ /^\d+$/;
|
|
|
+ $count = 1 if ( $count !~ /^\d+$/ || $count < 1 );
|
|
|
+ $count = 500 if $count > 500;
|
|
|
my @response;
|
|
|
for ( 1 .. $count ) {
|
|
|
my $id = int rand 10000 + 1;
|
|
@@ -96,9 +97,9 @@ sub query {
|
|
|
}
|
|
|
else {
|
|
|
$sth[0]->execute($id);
|
|
|
- $row = $sth[0]->fetchrow_hashref
|
|
|
+ $row = $sth[0]->fetchrow_hashref;
|
|
|
}
|
|
|
- if ( $row ) {
|
|
|
+ if ($row) {
|
|
|
if ( $count == 1 ) {
|
|
|
return { id => $id, randomNumber => $row->{randomNumber} };
|
|
|
}
|
|
@@ -117,8 +118,13 @@ sub fortunes {
|
|
|
$res .= q[<body><table><tr><th>id</th><th>message</th></tr>];
|
|
|
|
|
|
for my $item ( sort { $a->{message} cmp $b->{message} } @$objects ) {
|
|
|
- my $id = $item->{id} // 1000;
|
|
|
+ my $id = $item->{id};
|
|
|
my $message = escape_html( $item->{message} );
|
|
|
+
|
|
|
+ # HTML::Escape encodes apostrophe as ' because IE8 does not
|
|
|
+ # support '. We forse an ' here in order to pass the
|
|
|
+ # test
|
|
|
+ $message =~ s/'/&apos/g;
|
|
|
$res .= "<tr><td>$id</td><td>$message</td></tr>";
|
|
|
}
|
|
|
|