Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newlines in the porter.yaml should be converted to \n in the json #1444

Closed
carolynvs opened this issue Feb 10, 2021 · 2 comments
Closed

Newlines in the porter.yaml should be converted to \n in the json #1444

carolynvs opened this issue Feb 10, 2021 · 2 comments
Assignees
Labels
1 - 🍫 Eat chocolate _after_ emergency donuts bug Oops, sorry! cnab Related to the CNAB spec
Milestone

Comments

@carolynvs
Copy link
Member

Describe the bug

I created a bundle and used newlines in some description fields. When the bundle.json was created, the newlines were preserved instead of converted to \n. This caused the bundle.json to not be valid json.

To Reproduce

  1. porter create
  2. Edit the porter.yaml and make the description multi-line
name: porter-hello
description: |-
  I am a great bundle
  So great it takes two lines to describe me
  1. porter build

Look at the .cnab/bundle.json and note that there are newlines in the description field

Expected behavior

  1. We should validate the generated bundle.json before building the invocation image. This should have failed porter build but it didn't.
  2. The generated bundle.json should change newlines to \n characters when writing the bundle.json. I would have assumed that the json marshal command would handle that for us but I guess it doesn't. So we should fixup any strings we set to do the conversion ourselves.

Porter Command and Output

Here is the misbehaving bundle.json

{"custom":{"sh.porter":{"manifest":"IyBUaGlzIGlzIHRoZSBjb25maWd1cmF0aW9uIGZvciBQb3J0ZXIKIyBZb3UgbXVzdCBkZWZpbmUgc3RlcHMgZm9yIGVhY2ggYWN0aW9uLCBidXQgdGhlIHJlc3QgaXMgb3B0aW9uYWwKIyBTZWUgaHR0cHM6Ly9wb3J0ZXIuc2gvYXV0aG9yLWJ1bmRsZXMgZm9yIGRvY3VtZW50YXRpb24gb24gaG93IHRvIGNvbmZpZ3VyZSB5b3VyIGJ1bmRsZQojIFVuY29tbWVudCBvdXQgdGhlIHNlY3Rpb25zIGJlbG93IHRvIHRha2UgZnVsbCBhZHZhbnRhZ2Ugb2Ygd2hhdCBQb3J0ZXIgY2FuIGRvIQoKbmFtZ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hdXRob3ItYnVuZGxlcy8jY3JlZGVudGlhbHMKI2NyZWRlbnRpYWxzOgojICAtIG5hbWU6IGt1YmVjb25maWcKIyAgICBwYXRoOiAvcm9vdC8ua3ViZS9jb25maWcKIyAgLSBuYW1lOiB1c2VybmFtZQojICAgIGVudjogVVNFUk5BTUUKCiMgQmVsb3cgaXMgYW4gZXhhbXBsZSBvZiBob3cgdG8gZGVmaW5lIHBhcmFtZXRlcnMKIyBTZWUgaHR0cHM6Ly9wb3J0ZXIuc2gvYXV0aG9yLWJ1bmRsZXMvI3BhcmFtZXRlcnMKI3BhcmFtZXRlcnM6CiMgIC0gbmFtZTogbXlzcWxfdXNlcgojICAgIHR5cGU6IHN0cmluZwojICAgIGRlZmF1bHQ6IHdvcmRwcmVzcwo=","manifestDigest":"bef91602c0af93df9c50e2c2473a9a054d71e3bc796e6e7c6cbd0b40e84add26","mixins":{"exec":{}}},"sh.porter.file-parameters":{}},"definitions":{"porter-debug-parameter":{"$comment":"porter-internal","$id":"https://porter.sh/generated-bundle/#porter-debug","default":false,"description":"Print debug information from Porter when executing the bundle","type":"boolean"}},"description":"An example Porter configuration
With lots of text","invocationImages":[{"image":"getporter/porter-hello-installer:v0.1.0","imageType":"docker"}],"name":"porter-hello","parameters":{"porter-debug":{"definition":"porter-debug-parameter","description":"Print debug information from Porter when executing the bundle","destination":{"env":"PORTER_DEBUG"}}},"requiredExtensions":["sh.porter.file-parameters"],"schemaVersion":"v1.0.0","version":"0.1.0"}

Version

v0.33.0

@carolynvs carolynvs added the bug Oops, sorry! label Feb 10, 2021
@carolynvs carolynvs added the 1 - 🍫 Eat chocolate _after_ emergency donuts label Feb 10, 2021
@carolynvs carolynvs added the cnab Related to the CNAB spec label May 10, 2021
@carolynvs carolynvs added this to the 1.0 milestone May 10, 2021
@vdice vdice self-assigned this May 12, 2021
@vdice
Copy link
Member

vdice commented May 12, 2021

I wanted to first try to build Porter with the cnab-go version in the following staged PR from Carolyn: cnabio/cnab-go#247

Sure enough, with that version (which uses a different canonical json library), we get the fix for free (\n chars substituted in where applicable) when marshal-ing the bundle. No extra code need be added to Porter! 🎉

Therefore, I propose we just sit on this and wait for it to be closed when Porter integrates the changes in the aforementioned PR.

@vdice
Copy link
Member

vdice commented Jun 4, 2021

I can confirm that this issue is fixed as of ed52bc1 on the v1 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - 🍫 Eat chocolate _after_ emergency donuts bug Oops, sorry! cnab Related to the CNAB spec
Projects
None yet
Development

No branches or pull requests

2 participants