From 7ef71cd21f45c9b22fc0ab8e75dad78fa8851f94 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 8 Oct 2022 17:21:34 -0700 Subject: [PATCH 1/2] src/libexpr/primops.cc: parseDrvName: make documentation follow implementation The documentation for `parseDrvName` does not agree with the implementation when the derivation name contains a dash which is followed by something that is neither a letter nor a digit. This commit corrects the documentation to agree with the implementation. --- src/libexpr/primops.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 28b998474..840bfecef 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -3821,8 +3821,8 @@ static RegisterPrimOp primop_parseDrvName({ .args = {"s"}, .doc = R"( Split the string *s* into a package name and version. The package - name is everything up to but not including the first dash followed - by a digit, and the version is everything following that dash. The + name is everything up to but not including the first dash not followed + by a letter, and the version is everything following that dash. The result is returned in a set `{ name, version }`. Thus, `builtins.parseDrvName "nix-0.12pre12876"` returns `{ name = "nix"; version = "0.12pre12876"; }`. From 5e24863d5a47b4fc99ab3c03e3903fc11de142f6 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 8 Oct 2022 17:23:03 -0700 Subject: [PATCH 2/2] tests/lang/eval-okay-versions.nix: add test for previous commit This commit adds a test covering the discrepancy between parseDrvName's implementation and documentation (the discrepancy was eliminated in the previous commit). --- tests/lang/eval-okay-versions.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/lang/eval-okay-versions.nix b/tests/lang/eval-okay-versions.nix index e63c36586..e9111f5f4 100644 --- a/tests/lang/eval-okay-versions.nix +++ b/tests/lang/eval-okay-versions.nix @@ -4,6 +4,7 @@ let name2 = "hello"; name3 = "915resolution-0.5.2"; name4 = "xf86-video-i810-1.7.4"; + name5 = "name-that-ends-with-dash--1.0"; eq = 0; lt = builtins.sub 0 1; @@ -23,6 +24,8 @@ let ((builtins.parseDrvName name3).version == "0.5.2") ((builtins.parseDrvName name4).name == "xf86-video-i810") ((builtins.parseDrvName name4).version == "1.7.4") + ((builtins.parseDrvName name5).name == "name-that-ends-with-dash") + ((builtins.parseDrvName name5).version == "-1.0") (versionTest "1.0" "2.3" lt) (versionTest "2.1" "2.3" lt) (versionTest "2.3" "2.3" eq)