From 8135a8d38cefdc4632b3c85fdbb663d067f91248 Mon Sep 17 00:00:00 2001 From: Aspen Smith Date: Tue, 5 Dec 2023 17:11:45 -0500 Subject: fix(tvix/eval): Return error rather than panicking on bad substring If builtins.substring is invoked with (byte!!) offsets that aren't at codepoint boundaries, return an error rather than panicking. This is still incorrect (see b/337) but pushes the incorrectness forward a step. Change-Id: I5a4261f2ff250874cd36489ef598dcf886669d04 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10199 Tested-by: BuildkiteCI Autosubmit: grfn Reviewed-by: sterni --- tvix/eval/src/builtins/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tvix/eval/src/builtins') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index f9302deab84b..ead916377f94 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -951,7 +951,7 @@ mod pure_builtins { cmp::min(beg + (len as usize), x.as_str().len()) }; - Ok(Value::String(x.as_str()[beg..end].into())) + Ok(Value::String(x.as_bytes()[beg..end].try_into()?)) } #[builtin("tail")] -- cgit 1.4.1