Skip to content

Commit

Permalink
Protect pretty print against errors caused because a MathObject hasn'…
Browse files Browse the repository at this point in the history
…t been properly stringified.

This doesn't solve the basic issue which is to make sure that objects are stringified before leaving the Safe compartment.  This does however make the error messages more useful when that happens.
  • Loading branch information
mgage committed Jan 23, 2016
1 parent 8d5e763 commit 1b2ef07
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/PGUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ sub pretty_print_html { # provides html output -- NOT a method
$level--;
return "PGalias has too much info. Try \$PG->{PG_alias}->{resource_list}" if ref($r_input) eq 'PGalias'; # PGalias just has too much information
return 'too deep' unless $level > 0; # only print four levels of hashes (safety feature)
my $out = '';
my $out = '';
# protect against modules defined in Safe which can't find their stringify procedure.
$r_input = $r_input//'';
eval { "$r_input" };
if ($@ ) {
$out = "Unable to determine stringify this item\n";
$out .= $@. "\n";
return ($out);
}


if ( not ref($r_input) ) {
$out = $r_input if defined $r_input; # not a reference
$out =~ s/</&lt;/g ; # protect for HTML output
Expand Down

0 comments on commit 1b2ef07

Please sign in to comment.