From a3dbb60213fad39f73f6a03fb5e14eaa09b85670 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Thu, 24 Aug 2023 02:14:21 +0200 Subject: fix(tvix/eval): off-by-one in replaceStrings replaceStrings would previously fail to replace the last character in a string. Change-Id: I43a7c960945350b2e7a5b731b7fdb617723eb38f Reviewed-on: https://cl.tvl.fyi/c/depot/+/9151 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/builtins/mod.rs | 2 +- tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp | 2 +- tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'tvix/eval/src') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index d0c5bf5568b9..d701fa08a08d 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -723,7 +723,7 @@ mod pure_builtins { let from = elem.0.to_str()?; let to = elem.1.to_str()?; - if i + from.len() >= string.len() { + if i + from.len() > string.len() { continue; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp index c2cb89bac663..9f20496c7aa0 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp @@ -1 +1 @@ -[ "fabir" "a" "1a1" ] +[ "fabir" "a" "1a1" "ABC" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix index b8101c448bb0..24a58996094a 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix @@ -2,4 +2,5 @@ (builtins.replaceStrings ["oo" "a"] ["a" "i"] "foobar") (builtins.replaceStrings ["o"] ["a"] "a") (builtins.replaceStrings ["" ""] ["1" "2"] "a") + (builtins.replaceStrings ["a" "b" "c"] ["A" "B" "C"] "abc") ] -- cgit 1.4.1