summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2022-05-02 09:47:15 +0200
committerGitHub <noreply@github.com>2022-05-02 09:47:15 +0200
commit761c21a16a4a6e18909f5a9a81139b515a11bfd9 (patch)
tree1a52b7e9c062bf689f26fcc143d0f2d35710f181 /lib
parent807011966b4e00fdf174c8ba5c496f47d084fa26 (diff)
parent7b5be1a0f8e8b0298dd71d78ec01de704d151f3b (diff)
downloadnixpkgs-761c21a16a4a6e18909f5a9a81139b515a11bfd9.tar
nixpkgs-761c21a16a4a6e18909f5a9a81139b515a11bfd9.tar.gz
nixpkgs-761c21a16a4a6e18909f5a9a81139b515a11bfd9.tar.bz2
nixpkgs-761c21a16a4a6e18909f5a9a81139b515a11bfd9.tar.lz
nixpkgs-761c21a16a4a6e18909f5a9a81139b515a11bfd9.tar.xz
nixpkgs-761c21a16a4a6e18909f5a9a81139b515a11bfd9.tar.zst
nixpkgs-761c21a16a4a6e18909f5a9a81139b515a11bfd9.zip
Merge pull request #170090 from danth/has-infix-toString
lib/strings: call toString within hasInfix
Diffstat (limited to 'lib')
-rw-r--r--lib/strings.nix2
-rw-r--r--lib/tests/misc.nix30
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index d3ef748fb71..328f64cf1b6 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -254,7 +254,7 @@ rec {
       => false
   */
   hasInfix = infix: content:
-    builtins.match ".*${escapeRegex infix}.*" content != null;
+    builtins.match ".*${escapeRegex infix}.*" "${content}" != null;
 
   /* Convert a string to a list of characters (i.e. singleton strings).
      This allows you to, e.g., map a function over each character.  However,
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index f7e62a71eee..faa7ee547f5 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -280,6 +280,36 @@ runTests {
     '';
   };
 
+  testHasInfixFalse = {
+    expr = hasInfix "c" "abde";
+    expected = false;
+  };
+
+  testHasInfixTrue = {
+    expr = hasInfix "c" "abcde";
+    expected = true;
+  };
+
+  testHasInfixDerivation = {
+    expr = hasInfix "hello" (import ../.. { system = "x86_64-linux"; }).hello;
+    expected = true;
+  };
+
+  testHasInfixPath = {
+    expr = hasInfix "tests" ./.;
+    expected = true;
+  };
+
+  testHasInfixPathStoreDir = {
+    expr = hasInfix builtins.storeDir ./.;
+    expected = true;
+  };
+
+  testHasInfixToString = {
+    expr = hasInfix "a" { __toString = _: "a"; };
+    expected = true;
+  };
+
 # LISTS
 
   testFilter = {