awslabs / aws-cfn-template-flip

Tool for converting AWS CloudFormation templates between JSON and YAML formats.
Apache License 2.0
994 stars 142 forks source link

Cfn-flip fails to parse YAMLs when there is a tab character #117

Open JoseRolles opened 2 years ago

JoseRolles commented 2 years ago

This doesn't work:

Parameters:
  Test:
    Type: String
    Default: Tab here ->    <- tab here
Resources:
  S3:
    Type: AWS::Logs::LogGroup

This works:

Parameters:
  Test:
    Type: String
    Default: "Tab here ->\t<- tab here"
Resources:
  S3:
    Type: AWS::Logs::LogGroup

When using AWS CloudFormation Designer, somehow it still validates without issue.

koiker commented 2 years ago

Hi Jose,

Let me run some tests.

koiker commented 2 years ago

I was able to replicate the issue and found that this is a bug in PyYaml accordingly to this thread: https://github.com/yaml/pyyaml/issues/594 I will think in how we can solve this issue by:

w0rmr1d3r commented 2 years ago

Hello to both of you!

I happen to have the same (or similar) error. When trying to "parse" a template in YAML, it fails for me in: https://github.com/awslabs/aws-cfn-template-flip/blob/master/cfn_flip/__init__.py#L27 raising:

JSONDecodeError
Expecting value: line 1 column 1 (char 0)

When either a str or bytes is passed as the parameter and including a tab character, in any of its forms \t or <tab character> (being the second one just a tab in the IDE.

I tried to "clean" tabs (can do in its first form) when in a str before calling the function and it works, but no clue on the second type of tab.

Is it the same error? Any clue?

Thank you both in advance!