NixExprs: extract the `escape` function and test it
[?]
Mar 17, 2021, 3:07 PM
S2KNQCPB22URM7BLFSMADPWPQGBOZWMYHBPIW4N6PNEFVDUTYWWQCDependencies
- [2]
2JJP7673tests: move to t, allow `yath test` from root - [3]
FG4JZPWSHandle builds with multiple outputs correctly in Hydra channels - [4]
UZENK33P* Generate a .tar.bz2 file for the channel Nix expression, since - [5]
VMBIK4GUNixExprs.pm: encode default.nix as utf-8 to fix missing chars/data. (#455) - [6]
L5Z6CN7MIn Hydra channels, show only packages matching the user's system type - [7]
I42G2Z7P* Escape string literals.[ - [8]
PDZXZZPZShut up some Perl 5.20 warnings - [9]
4CELXP7PRemove the longDescription field - [10]
LVJKRTIK* Generate a Nix expression for the channel. - [*]
D5QIOJGP* Move everything up one directory.
Change contents
- file addition: Escape.pm[12.339]
package Hydra::Helper::Escape;use strict;use base qw(Exporter);our @EXPORT = qw(escapeString);sub escapeString {my ($s) = @_;$s =~ s|\\|\\\\|g;$s =~ s|\"|\\\"|g;$s =~ s|\$|\\\$|g;return "\"" . $s . "\"";} - edit in src/lib/Hydra/View/NixExprs.pm at line 6
use Hydra::Helper::Escape; - edit in src/lib/Hydra/View/NixExprs.pm at line 12
sub escape {my ($s) = @_;$s =~ s|\\|\\\\|g;$s =~ s|\"|\\\"|g;$s =~ s|\$|\\\$|g;return "\"" . $s . "\"";} - edit in src/lib/Hydra/View/NixExprs.pm at line 13
- replacement in src/lib/Hydra/View/NixExprs.pm at line 58
$res .= "if system == ${\escape $system} then {\n\n";$res .= "if system == ${\escapeString $system} then {\n\n"; - replacement in src/lib/Hydra/View/NixExprs.pm at line 66
$res .= " ${\escape $attr} = (mkFakeDerivation {\n";$res .= " ${\escapeString $attr} = (mkFakeDerivation {\n"; - replacement in src/lib/Hydra/View/NixExprs.pm at line 68
$res .= " name = ${\escape ($build->get_column('releasename') or $build->nixname)};\n";$res .= " system = ${\escape $build->system};\n";$res .= " name = ${\escapeString ($build->get_column('releasename') or $build->nixname)};\n";$res .= " system = ${\escapeString $build->system};\n"; - replacement in src/lib/Hydra/View/NixExprs.pm at line 71
$res .= " description = ${\escape $build->description};\n"$res .= " description = ${\escapeString $build->description};\n" - replacement in src/lib/Hydra/View/NixExprs.pm at line 73
$res .= " license = ${\escape $build->license};\n"$res .= " license = ${\escapeString $build->license};\n" - replacement in src/lib/Hydra/View/NixExprs.pm at line 75
$res .= " maintainers = ${\escape $build->maintainers};\n"$res .= " maintainers = ${\escapeString $build->maintainers};\n" - replacement in src/lib/Hydra/View/NixExprs.pm at line 80
$res .= " ${\escape $_} = ${\escape $pkg->{outputs}->{$_}};\n" foreach @outputNames;$res .= " ${\escapeString $_} = ${\escapeString $pkg->{outputs}->{$_}};\n" foreach @outputNames; - file addition: Helper[2.697]
- file addition: escape.t[0.981]
use strict;use Setup;use Data::Dumper;use Test2::V0;use Hydra::Helper::Escape;subtest "checking individual attribute set elements" => sub {my %values = ("" => '""',"." => '"."',"foobar" => '"foobar"',"foo.bar" => '"foo.bar"',"🌮" => '"🌮"','foo"bar' => '"foo\"bar"','foo\\bar' => '"foo\\\\bar"','$bar' => '"\\$bar"',);for my $input (keys %values) {my $value = $values{$input};is(escapeString($input), $value, "Escaping the value: " . $input);}};done_testing;