From 7a0811c24b36c60d6254271aa003e13f37ced55d Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Fri, 15 May 2026 23:30:21 -0400 Subject: [PATCH] lib.strings.hasInfix: compute escaped infix early --- lib/strings.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/strings.nix b/lib/strings.nix index 0db098662787..747d15d119c0 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -904,6 +904,9 @@ rec { */ hasInfix = infix: + let + escapedInfix = escapeRegex infix; + in if isPath infix then # Before 23.05, paths would be copied to the store before converting them # to strings and comparing. This was surprising and confusing. @@ -912,7 +915,7 @@ rec { There is almost certainly a bug in the calling code, since this function always returns `false` in such a case. This function also copies the path to the Nix store, which may not be what you want.'' else - content: builtins.match ".*${escapeRegex infix}.*" "${content}" != null; + content: builtins.match ".*${escapedInfix}.*" "${content}" != null; /** Convert a string `s` to a list of characters (i.e. singleton strings).