Skip to content

Commit

Permalink
getNameFromURL(): Support uppercase characters in attribute names
Browse files Browse the repository at this point in the history
In particular, this makes it handle 'legacyPackages' correctly.

(cherry picked from commit 936a364)

Upstream-PR: NixOS/nix#9657
Change-Id: Icc4efe02f7f8e90a2970589f72fd3d3cd4418d95
  • Loading branch information
edolstra authored and Qyriad committed May 2, 2024
1 parent efc7d23 commit 5cec872
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/libutil/url-name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace nix {

static std::string const attributeNamePattern("[a-z0-9_-]+");
static std::string const attributeNamePattern("[a-zA-Z0-9_-]+");
static std::regex const lastAttributeRegex("(?:" + attributeNamePattern + "\\.)*(?!default)(" + attributeNamePattern +")(\\^.*)?");
static std::string const pathSegmentPattern("[a-zA-Z0-9_-]+");
static std::regex const lastPathSegmentRegex(".*/(" + pathSegmentPattern +")");
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/libutil/url-name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ namespace nix {

/* ----------- tests for url-name.hh --------------------------------------------------*/

TEST(getNameFromURL, getsNameFromURL) {
TEST(getNameFromURL, getNameFromURL) {
ASSERT_EQ(getNameFromURL(parseURL("path:/home/user/project")), "project");
ASSERT_EQ(getNameFromURL(parseURL("path:~/repos/nixpkgs#packages.x86_64-linux.hello")), "hello");
ASSERT_EQ(getNameFromURL(parseURL("path:.#nonStandardAttr.mylaptop")), "nonStandardAttr.mylaptop");
ASSERT_EQ(getNameFromURL(parseURL("path:./repos/myflake#nonStandardAttr.mylaptop")), "nonStandardAttr.mylaptop");
ASSERT_EQ(getNameFromURL(parseURL("path:~/repos/nixpkgs#legacyPackages.x86_64-linux.hello")), "hello");
ASSERT_EQ(getNameFromURL(parseURL("path:~/repos/nixpkgs#packages.x86_64-linux.Hello")), "Hello");
ASSERT_EQ(getNameFromURL(parseURL("path:.#nonStandardAttr.mylaptop")), "mylaptop");
ASSERT_EQ(getNameFromURL(parseURL("path:./repos/myflake#nonStandardAttr.mylaptop")), "mylaptop");
ASSERT_EQ(getNameFromURL(parseURL("path:./nixpkgs#packages.x86_64-linux.complex^bin,man")), "complex");
ASSERT_EQ(getNameFromURL(parseURL("path:./myproj#packages.x86_64-linux.default^*")), "myproj");

Expand Down

0 comments on commit 5cec872

Please sign in to comment.