From bf30e8108f64b5919b8793fd2124c5c33a96ef91 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sat, 04 May 2024 21:43:53 +0000 Subject: [PATCH] fix: ObjValue is_empty should not account hidden fields --- --- a/crates/jrsonnet-evaluator/src/obj.rs +++ b/crates/jrsonnet-evaluator/src/obj.rs @@ -669,17 +669,18 @@ } fn len(&self) -> usize { + // Maybe it will be better to not compute sort key here? self.fields_visibility() .into_iter() .filter(|(_, (visible, _))| *visible) .count() } + /// Returns false only if there is any visible entry. + /// + /// Note that object with hidden fields `{a:: 1}` will be reported as empty here. fn is_empty(&self) -> bool { - if !self.this_entries.is_empty() { - return false; - } - self.sup.as_ref().map_or(true, ObjValue::is_empty) + self.len() != 0 } /// Run callback for every field found in object --- a/crates/jrsonnet-stdlib/src/strings.rs +++ b/crates/jrsonnet-stdlib/src/strings.rs @@ -28,9 +28,9 @@ } #[builtin] -pub fn builtin_escape_string_bash(str: String) -> String { +pub fn builtin_escape_string_bash(str_: String) -> String { const QUOTE: char = '\''; - let mut out = str.replace(QUOTE, "'\"'\"'"); + let mut out = str_.replace(QUOTE, "'\"'\"'"); out.insert(0, QUOTE); out.push(QUOTE); out -- gitstuff