Skip to content

Commit

Permalink
Enable l1-output-string
Browse files Browse the repository at this point in the history
This required two fixes.

Firstly when reading in a literal string from PCL we need to re-escape
any `$${` escape sequences.

Secondly it's valid to have an empty string as a stack export. We fix
this by making sure empty strings from PCL write out as `""` rather than
nothing, as the latter caused the yaml runtime to think it was an
empty/null/missing key rather than an empty string.
  • Loading branch information
Frassle committed Nov 14, 2024
1 parent 8e8c6f4 commit 962a71a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Bug Fixes-675.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
component: codegen
kind: Bug Fixes
body: Maintain empty strings in converted programs to still be string literals in
YAML
time: 2024-11-14T15:15:07.587566353Z
custom:
PR: "675"
1 change: 0 additions & 1 deletion cmd/pulumi-language-yaml/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func runTestingHost(t *testing.T) (string, testingrpc.LanguageTestClient) {
// Add test names here that are expected to fail and the reason why they are failing
var expectedFailures = map[string]string{
"l1-stack-reference": "TODO",
"l1-output-string": "TODO",
"l2-destroy": "TODO",
"l2-invoke-options": "TODO",
"l2-map-keys": "TODO",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
outputs:
empty:
empty: ""
small: Hello world!
emoji: "\U0001F44B \"Hello \U0001019B!\" \U0001F60A"
escape: "Some ${common} \"characters\" 'that' need escaping: \\ (backslash), \t (tab), \e (escape), \a (bell), \0 (null), \U000E0021 (tag space)"
escapeNewline: "Some ${common} \"characters\" 'that' need escaping: \\ (backslash), \n (newline), \t (tab), \e (escape), \a (bell), \0 (null), \U000E0021 (tag space)"
escape: "Some $${common} \"characters\" 'that' need escaping: \\ (backslash), \t (tab), \e (escape), \a (bell), \0 (null), \U000E0021 (tag space)"
escapeNewline: "Some $${common} \"characters\" 'that' need escaping: \\ (backslash), \n (newline), \t (tab), \e (escape), \a (bell), \0 (null), \U000E0021 (tag space)"
large: |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Expand Down
2 changes: 2 additions & 0 deletions pkg/pulumiyaml/codegen/gen_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ func (g *generator) expr(e model.Expression) syn.Node {
return syn.Null()
case t.Equals(cty.String):
v := e.Value.AsString()
// This is a literal string so escape any ${ sequences in it
v = strings.ReplaceAll(v, "${", "$${")
return syn.String(v)
case t.Equals(cty.Number):
v := e.Value.AsBigFloat()
Expand Down
4 changes: 4 additions & 0 deletions pkg/pulumiyaml/syntax/encoding/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ func MarshalYAML(n syntax.Node) (*yaml.Node, syntax.Diagnostics) {
if originalValue != value {
yamlNode.Value = value
}
// if the empty string use double quotes so we get "" instead of nothing
if yamlNode.Value == "" {
yamlNode.Style = yaml.DoubleQuotedStyle
}
case *syntax.ListNode:
if yamlNode.Kind != yaml.SequenceNode && yamlNode.Kind != yaml.DocumentNode {
yamlNode.Kind = yaml.SequenceNode
Expand Down

0 comments on commit 962a71a

Please sign in to comment.