Skip to content

std.parseYaml() - new test case fails... #942

@pmorch

Description

@pmorch

std.parseYaml() exists in the cpp version in the master branch since commit da1490f. It was introduced by the merge of #899 and the main issue about its introduction is (I think) #460. A release hasn't been made with it yet.

std.parseYaml() chokes on this (I think) valid YAML,:

f1: |
  a
  b
f2: "a\nb"

Running it through std.parseYaml() gives an error:

Something went wrong during jsonnet_evaluate_snippet, please report this: [json.exception.parse_error.101] parse error at line 2, column 0: syntax error while parsing value - invalid string: control character U+000A (LF) must be escaped to \u000A or \n; last read: '"a<U+000A>'
[1]    91637 abort      ./jsonnet parseYaml.jsonnet

Where it should be fine and equal { f1: 'a\nb', f2: 'a\nb' }.

This is a patch for the test_suite to test for it. (Easy to add as a PR - let me know if you want a PR for this...)

diff --git a/test_suite/stdlib.jsonnet b/test_suite/stdlib.jsonnet
index 669c1f9..257c9d5 100644
--- a/test_suite/stdlib.jsonnet
+++ b/test_suite/stdlib.jsonnet
@@ -1467,6 +1467,16 @@ std.assertEqual(
     |||
   ), [1, 2, 3]
 ) &&
+std.assertEqual(
+  std.parseYaml(
+    |||
+      f1: |
+        a
+        b
+      f2: "a\nb"
+    |||
+  ), { f1: 'a\nb', f2: 'a\nb' }
+) &&
 
 std.assertEqual(std.asciiUpper('!@#$%&*()asdfghFGHJKL09876 '), '!@#$%&*()ASDFGHFGHJKL09876 ') &&
 std.assertEqual(std.asciiLower('!@#$%&*()asdfghFGHJKL09876 '), '!@#$%&*()asdfghfghjkl09876 ') &&

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions