nix-channel --add: Validate URL / channel ID

Fixes #369.
This commit is contained in:
Eelco Dolstra 2014-10-14 11:28:13 +02:00
parent f1adf4c998
commit a8925a510c

View file

@ -61,6 +61,8 @@ sub writeChannels {
# Adds a channel.
sub addChannel {
my ($url, $name) = @_;
die "invalid channel URL $url" unless $url =~ /^(file|http|https):\/\//;
die "invalid channel identifier $name" unless $name =~ /^[a-zA-Z0-9_][a-zA-Z0-9_\-\.]*$/;
readChannels;
$channels{$name} = $url;
writeChannels;