difftreelog
fix string index bounds check
in: master
2 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -36,6 +36,8 @@
#[error("array out of bounds: {0} is not within [0,{1})")]
ArrayBoundsError(usize, usize),
+ #[error("string out of bounds: {0} is not within [0,{1})")]
+ StringBoundsError(usize, usize),
#[error("assert failed: {0}")]
AssertionFailed(IStr),
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth589 n.value_type(),589 n.value_type(),590 )),590 )),591591592 (Val::Str(s), Val::Num(n)) => Val::Str(592 (Val::Str(s), Val::Num(n)) => Val::Str({593 s.chars()593 let v: IStr = s594 .chars()594 .skip(n as usize)595 .skip(n as usize)595 .take(1)596 .take(1)596 .collect::<String>()597 .collect::<String>()597 .into(),598 .into();599 if v.is_empty() {600 let size = s.chars().count();601 throw!(StringBoundsError(n as usize, size))602 }603 v598 ),604 }),599 (Val::Str(_), n) => throw!(ValueIndexMustBeTypeGot(605 (Val::Str(_), n) => throw!(ValueIndexMustBeTypeGot(600 ValType::Str,606 ValType::Str,601 ValType::Num,607 ValType::Num,