From 830d8fba206ac620bed8693282e225ffbf3bdc57 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sun, 05 Apr 2026 19:25:11 +0000 Subject: [PATCH] fix: yaml stream handling difference --- --- a/crates/jrsonnet-stdlib/src/parse.rs +++ b/crates/jrsonnet-stdlib/src/parse.rs @@ -9,7 +9,9 @@ #[builtin] pub fn builtin_parse_yaml(str: IStr) -> Result { - let out = serde_saphyr::from_multiple_with_options::( + let needs_synthetic_null = str.trim_end().ends_with("\n---"); + + let mut out = serde_saphyr::from_multiple_with_options::( &str, serde_saphyr::Options { // Golang/C++ compat @@ -20,6 +22,13 @@ }, ) .map_err(|e| runtime_error!("failed to parse yaml: {e}"))?; + + // saphyr and other yaml implementations disagree on how to handle an empty document in multi-document stream. + // Saphyr only considers document started after anything is emitted after the document delimiter + if needs_synthetic_null { + out.push(Val::Null); + } + Ok(if out.is_empty() { Val::Null } else if out.len() == 1 { -- gitstuff