From 3de462823c513bc7a3ef894f21c83b2321b3648a Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sat, 4 May 2024 23:43:53 +0200 Subject: [PATCH] fix: ObjValue is_empty should not account hidden fields --- crates/jrsonnet-evaluator/src/obj.rs | 9 +++++---- crates/jrsonnet-stdlib/src/strings.rs | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/jrsonnet-evaluator/src/obj.rs b/crates/jrsonnet-evaluator/src/obj.rs index 672d2505..765c0941 100644 --- a/crates/jrsonnet-evaluator/src/obj.rs +++ b/crates/jrsonnet-evaluator/src/obj.rs @@ -669,17 +669,18 @@ impl ObjectLike for OopObject { } 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 diff --git a/crates/jrsonnet-stdlib/src/strings.rs b/crates/jrsonnet-stdlib/src/strings.rs index 6f9327da..39a2281b 100644 --- a/crates/jrsonnet-stdlib/src/strings.rs +++ b/crates/jrsonnet-stdlib/src/strings.rs @@ -28,9 +28,9 @@ pub fn builtin_str_replace(str: String, from: IStr, to: IStr) -> String { } #[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