difftreelog
fix string index bounds check
in: master
2 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth363637 #[error("array out of bounds: {0} is not within [0,{1})")]37 #[error("array out of bounds: {0} is not within [0,{1})")]38 ArrayBoundsError(usize, usize),38 ArrayBoundsError(usize, usize),39 #[error("string out of bounds: {0} is not within [0,{1})")]40 StringBoundsError(usize, usize),394140 #[error("assert failed: {0}")]42 #[error("assert failed: {0}")]41 AssertionFailed(IStr),43 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,