about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2022-04-05 20:05:33 +0200
committerGitHub <noreply@github.com>2022-04-05 20:05:33 +0200
commit559ac3c9e792ae905497528d22e31f9fa9df5982 (patch)
treed3acba16e06763557797a8666198e96425fb515c /lib
parentf1aa084baa724e97e8aa24b28f6d000952a31340 (diff)
parentfffabe7500e972eb5275199c82a35132a07fa29f (diff)
Merge pull request #166383 from hercules-ci/always-sanitize-derivation-name
Always sanitize derivation name
Diffstat (limited to 'lib')
-rw-r--r--lib/strings.nix9
-rw-r--r--lib/tests/misc.nix5
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index d34263c994948..820d1901f945b 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -756,7 +756,14 @@ rec {
        sanitizeDerivationName pkgs.hello
        => "-nix-store-2g75chlbpxlrqn15zlby2dfh8hr9qwbk-hello-2.10"
   */
-  sanitizeDerivationName = string: lib.pipe string [
+  sanitizeDerivationName =
+  let okRegex = match "[[:alnum:]+_?=-][[:alnum:]+._?=-]*";
+  in
+  string:
+  # First detect the common case of already valid strings, to speed those up
+  if stringLength string <= 207 && okRegex string != null
+  then unsafeDiscardStringContext string
+  else lib.pipe string [
     # Get rid of string context. This is safe under the assumption that the
     # resulting string is only used as a derivation name
     unsafeDiscardStringContext
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 1eb2d953ebbe9..c7cef2a9059f1 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -649,6 +649,11 @@ runTests {
     expected = "foo";
   };
 
+  testSanitizeDerivationNameUnicode = testSanitizeDerivationName {
+    name = "fö";
+    expected = "f-";
+  };
+
   testSanitizeDerivationNameAscii = testSanitizeDerivationName {
     name = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
     expected = "-+--.-0123456789-=-?-ABCDEFGHIJKLMNOPQRSTUVWXYZ-_-abcdefghijklmnopqrstuvwxyz-";