Escape underscores in legend strings

Other characters have special meaning, too. But they haven't cropped up
yet. Anyway, don't run this on untrusted input.
This commit is contained in:
Peter J. Holzer 2020-02-15 12:11:42 +01:00
parent 77e8042783
commit cdd9f6fdd8
1 changed files with 3 additions and 2 deletions

View File

@ -424,10 +424,11 @@ sub plot {
$comma = 1;
}
my $legend = $self->{legend}[$i];
my $escaped_legend = $legend =~ s/_/\\_/gr;
if ($self->{style} eq 'filledcurves') {
print $ctlfh "'$datafn' using 1:(\$", $col++, "):(0) title '$legend'";
print $ctlfh "'$datafn' using 1:(\$", $col++, "):(0) title '$escaped_legend'";
} else {
print $ctlfh "'$datafn' using 1:(\$", $col++, ") title '$legend'";
print $ctlfh "'$datafn' using 1:(\$", $col++, ") title '$escaped_legend'";
}
if (my $color = $self->{colors}[$i]) {
print $ctlfh " linecolor rgbcolor '$color'";