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 = {