From e888c2133fb703d0161a6d7fb45f899289cb9729 Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Sun, 24 Apr 2022 14:17:43 +0100 Subject: [PATCH 1/2] lib/strings: convert to string within hasInfix This should fix the issue mentioned here: https://github.com/NixOS/nixpkgs/pull/168175#issuecomment-1107830574 --- lib/strings.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 7b5be1a0f8e8b0298dd71d78ec01de704d151f3b Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Wed, 27 Apr 2022 07:58:20 +0100 Subject: [PATCH 2/2] lib/tests: add tests for hasInfix Co-authored-by: Robert Hensing --- lib/tests/misc.nix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index c5d1d431677..a0be581d37f 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -271,6 +271,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 = {