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

Multi-line python string breaks with > character break YAML parser #211

Closed
cacack opened this issue Nov 16, 2023 · 3 comments
Closed

Multi-line python string breaks with > character break YAML parser #211

cacack opened this issue Nov 16, 2023 · 3 comments
Labels
bug Something isn't working investigating

Comments

@cacack
Copy link
Contributor

cacack commented Nov 16, 2023

I think this is similar/related to #110, in that various scenarios can break the YAML parsing. Here's another one:

Given this example YAML-based template:

AWSTemplateFormatVersion: "2010-09-09"

Description: Example AWS CloudFormation template snippet.

Resources:
  Test:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        ZipFile: |
          """Example."""

          import boto3

          breaks = """
          >
          """

          TEST = 1

It seems to be a combination of the multi-line string, the inclusion of the > on a newline in the string, and empty line trailing the multi-line string leads to breaking rain:

❯ rain fmt test.yaml
semantic difference after formatting:
(|) Resources:
(|)   Test:
(|)     Properties:
(|)       Code:
(>)         ZipFile: |
  "        ""Example."""
  i        mport boto3
  b        reaks = """
  >        
  "        ""
  T        EST = 1

If you change any of those factors up (e.g. move the > to the same line as the assignment, or remove the trailing empty line, etc), then the YAML is parsed correctly.

We uncovered this as our inline Python script used a multi-line string which contains some HTML.

@cacack
Copy link
Contributor Author

cacack commented Nov 16, 2023

I've found other similar issues with multi-line ZipFile attributes and some indication that the underlying go-yaml is the problem. Is it possible to just "ignore" the inline scripts? Something like remove the inline script, pass the rest of the YAML to the parser, apply the correct formatting, then re-insert the inline script back.. This way the contents of the inline aren't a factor anymore.

@ericzbeard ericzbeard added bug Something isn't working investigating labels Nov 16, 2023
@ericzbeard
Copy link
Contributor

That's a good idea. Fixing these issues has always resulted in some other problem cropping up. The trick would be figuring out where to re-insert the text into the formatted template.

@ericzbeard
Copy link
Contributor

Fixed by #222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigating
Projects
None yet
Development

No branches or pull requests

2 participants