Skip to content

Commit

Permalink
bug: dedent strings parsed within triple quote blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
hellovai committed Jan 30, 2025
1 parent 39b499d commit 1b2adde
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl From<JsonCollection> for Option<Value> {
}
JsonCollection::Array(values, completion_state) => Value::Array(values, completion_state),
JsonCollection::QuotedString(s, completion_state) => Value::String(s, completion_state),
JsonCollection::TripleQuotedString(s, completion_state) => Value::String(s, completion_state),
JsonCollection::TripleQuotedString(s, completion_state) => Value::String(dedent(s.as_str()).content, completion_state),
JsonCollection::SingleQuotedString(s, completion_state) => Value::String(s, completion_state),
JsonCollection::TripleBacktickString { content, .. } => {
let Some((fenced_codeblock_info, codeblock_contents)) = content.0.split_once("\n")
Expand Down
23 changes: 22 additions & 1 deletion engine/baml-lib/jsonish/src/tests/test_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,31 @@ test_deserializer!(
FieldType::class("Test"),
{
"type": "code",
"code": "\n\"Hello, world!\"\n"
"code": "\"Hello, world!\""
}
);


test_deserializer!(
triple_quotes_contains_only_quoted_string_dedent,
BAML_FILE,
r#"
{
"code": """
def main():
print("Hello, world!")
""",
"type": "code",
}
"#,
FieldType::class("Test"),
{
"type": "code",
"code": "def main():\n print(\"Hello, world!\")"
}
);


// test_deserializer!(
// triple_quotes_nested,
// BAML_FILE,
Expand Down

0 comments on commit 1b2adde

Please sign in to comment.