From cdd9f6fdd86db4fbd16e90372ecaf387ffdd19eb Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 15 Feb 2020 12:11:42 +0100 Subject: [PATCH] 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. --- TimeSeries.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TimeSeries.pm b/TimeSeries.pm index 3759090..68087b0 100644 --- a/TimeSeries.pm +++ b/TimeSeries.pm @@ -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'";