git.delta.rocks / jrsonnet / refs/commits / 035e8804c8a7

difftreelog

fix std.parseInt should accept + prefix

ylvprrxxYaroslav Bolyukin2026-06-24parent: #07fd802.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth
128128
129#[builtin]129#[builtin]
130pub fn builtin_parse_int(str: IStr) -> Result<f64> {130pub fn builtin_parse_int(str: IStr) -> Result<f64> {
131 if let Some(raw) = str.strip_prefix('-') {131 let (raw, sign) = str.strip_prefix('-').map_or_else(
132 || (str.strip_prefix('+').unwrap_or(&str), 1.0),
133 |neg| (neg, -1.0),
134 );
135
132 if raw.is_empty() {136 if raw.is_empty() {
133 bail!("integer only consists of a minus")137 bail!("empty integer string: {str:?}")
134 }138 }
135139
136 parse_nat::<10>(raw).map(|value| -value)140 Ok(parse_nat::<10>(raw)? * sign)
137 } else {
138 if str.is_empty() {
139 bail!("empty integer")
140 }
141
142 parse_nat::<10>(str.as_str())
143 }
144}141}
145142
146#[builtin]143#[builtin]
addedtests/suite/sjsonnet_issue_1030.jsonnetdiffbeforeafterboth

no changes