about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLinus Heckemann <git@sphalerite.org>2023-08-24T00·14+0200
committerLinus Heckemann <git@sphalerite.org>2023-08-24T10·07+0000
commita3dbb60213fad39f73f6a03fb5e14eaa09b85670 (patch)
treeadef67551d4046e65618d2fb4e7bf7f6aef79be4
parente9bbc5f2af35c9c303a20adfa3c805eb13db767f (diff)
fix(tvix/eval): off-by-one in replaceStrings r/6523
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 <sternenseemann@systemli.org>
-rw-r--r--tvix/eval/src/builtins/mod.rs2
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp2
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix1
3 files changed, 3 insertions, 2 deletions
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")
 ]