From 4d2cb75104e4a692c713e4b1fe2145fe8bdd6473 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 3 Mar 2009 09:37:16 +0000 Subject: [PATCH] * Escape string literals.[ --- src/Hydra/lib/Hydra/View/NixExprs.pm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Hydra/lib/Hydra/View/NixExprs.pm b/src/Hydra/lib/Hydra/View/NixExprs.pm index f3f467c7..b8a0012d 100644 --- a/src/Hydra/lib/Hydra/View/NixExprs.pm +++ b/src/Hydra/lib/Hydra/View/NixExprs.pm @@ -5,6 +5,15 @@ use base qw/Catalyst::View/; use Hydra::Helper::Nix; +sub escape { + my ($s) = @_; + $s =~ s|\\|\\\\|g; + $s =~ s|\"|\\\"|g; + $s =~ s|\$|\\\$|g; + return "\"" . $s . "\""; +} + + sub process { my ($self, $c) = @_; @@ -14,15 +23,15 @@ sub process { my $build = $c->stash->{nixPkgs}->{$name}; $res .= " # $name\n"; $res .= " { type = \"derivation\";\n"; - $res .= " name = \"" . ($build->resultInfo->releasename or $build->nixname) . "\";\n"; # !!! escaping? - $res .= " system = \"" . $build->system . "\";\n"; # idem + $res .= " name = " . escape ($build->resultInfo->releasename or $build->nixname) . ";\n"; + $res .= " system = " . (escape $build->system) . ";\n"; $res .= " outPath = " . $build->outpath . ";\n"; $res .= " meta = {\n"; - $res .= " description = \"" . $build->description . "\";\n" + $res .= " description = " . (escape $build->description) . ";\n" if $build->description; - $res .= " longDescription = \"" . $build->longdescription . "\";\n" + $res .= " longDescription = " . (escape $build->longdescription) . ";\n" if $build->longdescription; - $res .= " license = \"" . $build->license . "\";\n" + $res .= " license = " . (escape $build->license) . ";\n" if $build->license; $res .= " };\n"; $res .= " }\n";