Skip to content

Commit 67977f3

Browse files
handle NONE type result from rapidyaml parser
Fixes #1270
1 parent 338d4ed commit 67977f3

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

core/vm.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,9 @@ class Interpreter {
17031703
j.push_back(yamlTreeToJson(doc));
17041704
}
17051705
}
1706+
} else if (tree.type(tree.root_id()).is_notype()) {
1707+
scratch = makeNull();
1708+
return nullptr;
17061709
} else {
17071710
j = yamlTreeToJson(tree);
17081711
}

test_suite/stdlib.jsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,9 @@ std.assertEqual(std.parseJson('12'), 12) &&
14781478
std.assertEqual(std.parseJson('12.123'), 12.123) &&
14791479
std.assertEqual(std.parseJson('{"a": {"b": ["c", 42]}}'), { a: { b: ['c', 42] } }) &&
14801480

1481+
// Empty input evaluates to `null`.
1482+
// Regression test for https://github.com/google/jsonnet/issues/1270
1483+
std.assertEqual(std.parseYaml(' \n'), null) &&
14811484
std.assertEqual(std.parseYaml('{}'), {}) &&
14821485
std.assertEqual(std.parseYaml('[]'), []) &&
14831486
std.assertEqual(

0 commit comments

Comments
 (0)