Merge "Reject fully-qualified URLs in 'from' argument of nix registry add" into main
This commit is contained in:
@@ -85,8 +85,8 @@ std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
|
||||
+ "(?:#(" + queryRegex + "))?",
|
||||
std::regex::ECMAScript);
|
||||
|
||||
static std::regex flakeRegex(
|
||||
"((" + flakeIdRegexS + ")(?:/(?:" + refAndOrRevRegex + "))?)"
|
||||
static std::regex flakeShorthandRegex(
|
||||
flakeShorthandRegexS
|
||||
+ "(?:#(" + queryRegex + "))?",
|
||||
std::regex::ECMAScript);
|
||||
|
||||
@@ -95,7 +95,7 @@ std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
|
||||
/* Check if 'url' is a flake ID. This is an abbreviated syntax for
|
||||
'flake:<flake-id>?ref=<ref>&rev=<rev>'. */
|
||||
|
||||
if (std::regex_match(url, match, flakeRegex)) {
|
||||
if (std::regex_match(url, match, flakeShorthandRegex)) {
|
||||
auto parsedURL = ParsedURL{
|
||||
.url = url,
|
||||
.base = "flake:" + match.str(1),
|
||||
|
||||
@@ -46,4 +46,7 @@ const static std::string refAndOrRevRegex = "(?:(" + revRegexS + ")|(?:(" + refR
|
||||
const static std::string flakeIdRegexS = "[a-zA-Z][a-zA-Z0-9_-]*";
|
||||
extern std::regex flakeIdRegex;
|
||||
|
||||
const static std::string flakeShorthandRegexS = "((" + flakeIdRegexS + ")(?:/(?:" + refAndOrRevRegex + "))?)";
|
||||
extern std::regex flakeShorthandRegex;
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ std::regex refRegex(refRegexS, std::regex::ECMAScript);
|
||||
std::regex badGitRefRegex(badGitRefRegexS, std::regex::ECMAScript);
|
||||
std::regex revRegex(revRegexS, std::regex::ECMAScript);
|
||||
std::regex flakeIdRegex(flakeIdRegexS, std::regex::ECMAScript);
|
||||
std::regex flakeShorthandRegex(flakeShorthandRegexS, std::regex::ECMAScript);
|
||||
|
||||
ParsedURL parseURL(const std::string & url)
|
||||
{
|
||||
|
||||
@@ -31,8 +31,9 @@ R""(
|
||||
# Description
|
||||
|
||||
This command adds an entry to the user registry that maps flake
|
||||
reference *from-url* to flake reference *to-url*. If an entry for
|
||||
*from-url* already exists, it is overwritten.
|
||||
reference *from-url* to flake reference *to-url*, where *from-url*
|
||||
must be a shorthand like 'nixpkgs' or 'nixpkgs/nixos-20.03'. If an
|
||||
entry for *from-url* already exists, it is overwritten.
|
||||
|
||||
Entries can be removed using [`nix registry
|
||||
remove`](./nix3-registry-remove.md).
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "flake/flake.hh"
|
||||
#include "store-api.hh"
|
||||
#include "fetchers.hh"
|
||||
#include "url-parts.hh"
|
||||
#include "registry.hh"
|
||||
|
||||
using namespace nix;
|
||||
@@ -109,7 +110,14 @@ struct CmdRegistryAdd : MixEvalArgs, Command, RegistryCommand
|
||||
|
||||
void run() override
|
||||
{
|
||||
std::smatch match;
|
||||
if (!std::regex_match(fromUrl, match, flakeShorthandRegex)) {
|
||||
throw UsageError("'from-url' argument must be a shorthand like 'nixpkgs' or 'nixpkgs/nixos-20.03'");
|
||||
}
|
||||
auto fromRef = parseFlakeRef(fromUrl);
|
||||
if (fromRef.input.direct) {
|
||||
throw UsageError("'from-url' argument must be an indirect flakeref like 'nixpkgs' or 'flake:nixpkgs'");
|
||||
}
|
||||
auto toRef = parseFlakeRef(toUrl);
|
||||
auto registry = getRegistry();
|
||||
fetchers::Attrs extraAttrs;
|
||||
|
||||
Reference in New Issue
Block a user