Skip to content

Commit

Permalink
fix: ObjValue is_empty should not account hidden fields
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed May 17, 2024
1 parent 1b608b1 commit 3de4628
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions crates/jrsonnet-evaluator/src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/jrsonnet-stdlib/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3de4628

Please sign in to comment.