Skip to content

Commit beb581d

Browse files
docker: decode ascii encoded dockerarg strings
To support for example spaces via %20 Alternative implementation for pull request 965
1 parent 6e52084 commit beb581d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

build-recipe-docker

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ recipe_build_docker() {
227227
buildargs[${#buildargs[@]}]="$kv"
228228
;;
229229
esac
230-
done < <( queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" buildflags+ dockerarg )
230+
done < <( queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" --decode buildflags+ dockerarg )
231231

232232
if test -n "$BUILD_FLAVOR" ; then
233233
buildargs[${#buildargs[@]}]='--build-arg'

queryconfig

+19-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use strict;
2929
use Build;
3030
use Build::Rpm;
3131

32-
my ($dist, $archs, $configdir, $type, $argument);
32+
my ($dist, $archs, $configdir, $decode, $type, $argument);
3333

3434
$configdir = ($::ENV{'BUILD_DIR'} || '/usr/lib/build') . '/configs';
3535

@@ -42,6 +42,10 @@ while (@ARGV) {
4242
shift @ARGV;
4343
$archs = shift @ARGV;
4444
next;
45+
} elsif ($ARGV[0] eq '--decode') {
46+
shift @ARGV;
47+
$decode = 1;
48+
next;
4549
} elsif ($ARGV[0] eq '--configdir') {
4650
shift @ARGV;
4751
$configdir = shift @ARGV;
@@ -58,39 +62,45 @@ die("Please specify what to query\n") unless defined $type;
5862
my $cf = Build::read_config_dist($dist, $archs, $configdir);
5963
die("Unable to read config\n") unless $cf;
6064

65+
sub printout {
66+
my ($str) = @_;
67+
$str =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge if $decode;
68+
print $str;
69+
}
70+
6171
if ($type eq 'buildflags') {
6272
die("Specify which buildflag to query\n") unless $argument;
6373
my $result = $cf->{"buildflags:$argument"};
64-
print "$result\n" if defined $result;
74+
printout("$result\n") if defined $result;
6575
} elsif ($type eq 'buildflags+') {
6676
die("Specify which buildflag to query\n") unless $argument;
6777
for (@{$cf->{'buildflags'} || []}) {
68-
print "$1\n" if /\Q$argument\E:(.*)/;
78+
printout("$1\n") if /\Q$argument\E:(.*)/;
6979
}
7080
} elsif ($type eq 'hostarch') {
7181
my $result = $cf->{"hostarch"};
72-
print "$result\n" if defined $result;
82+
printout("$result\n") if defined $result;
7383
} elsif ($type eq 'target' || $type eq 'type' || $type eq 'binarytype' || $type eq 'buildengine' || $type eq 'rawmacros') {
74-
print "$cf->{$type}\n" if $cf->{$type};
84+
printout("$cf->{$type}\n") if $cf->{$type};
7585
} elsif ($type eq 'repotype' || $type eq 'repourl' || $type eq 'registryurl') {
76-
print join(' ', @{$cf->{$type}})."\n" if $cf->{$type};
86+
printout(join(' ', @{$cf->{$type}})."\n") if $cf->{$type};
7787
} elsif ($type eq 'optflags') {
7888
exit(0) unless $cf->{'optflags'};
7989
my $all = $cf->{'optflags'}->{'*'};
8090
$all = defined($all) && $all ne '' ? " $all" : '';
8191
$all .= " -g" if $argument && $argument eq 'debug';
8292
for (sort keys %{$cf->{'optflags'}}) {
8393
next if $_ eq '*';
84-
print "optflags: $_ $cf->{'optflags'}->{$_}$all\n";
94+
printout("optflags: $_ $cf->{'optflags'}->{$_}$all\n");
8595
}
8696
} elsif ($type eq 'substitute') {
8797
die("Specify which substitute to query\n") unless $argument;
8898
my @res = @{$cf->{'substitute'}->{$argument} || []};
89-
print join(' ', @res)."\n" if @res;
99+
printout(join(' ', @res)."\n")if @res;
90100
} elsif ($type eq 'eval') {
91101
die("Specify what to eval\n") unless defined $argument;
92102
my $result = Build::Rpm::expandmacros($cf, $argument);
93-
print "$result\n";
103+
printout("$result\n");
94104
} else {
95105
die("unsupported query type: $type\n");
96106
}

0 commit comments

Comments
 (0)