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

[BUG] Parsing error when comments used at EOF #228

Closed
sepehrdaddev opened this issue Dec 29, 2021 · 1 comment
Closed

[BUG] Parsing error when comments used at EOF #228

sepehrdaddev opened this issue Dec 29, 2021 · 1 comment
Labels
bug Something isn't working purple

Comments

@sepehrdaddev
Copy link
Contributor

sepehrdaddev commented Dec 29, 2021

Describe the bug
cfn-guard produces a parsing error when a comment is used without a \n at the end of line

To Reproduce
Please supply:

  • Rule used rule.guard:
let aws_ec2_volume_resources = Resources.*[ Type == 'AWS::EC2::Volume' ]
#EOF

Note:
Most of the text editors will add a \n character at the end of the file, easiest way to create the rule.guard file is to run the following command: printf "let aws_ec2_volume_resources = Resources.*[ Type == 'AWS::EC2::Volume' ]\n#EOF"> rule.guard

  • Template used template.json:
{
    "Resources":{
        "NewVolume":{
            "Type":"AWS::EC2::Volume",
            "Properties":{
                "Size":500,
                "Encrypted":false,
                "AvailabilityZone":"us-west-2b"
            }
        },
        "NewVolume2":{
            "Type":"AWS::EC2::Volume",
            "Properties":{
                "Size":100,
                "Encrypted":false,
                "AvailabilityZone":"us-west-2c"
            }
        }
    },
    "Parameters":{
        "InstanceName":"NewInstance"
    }
}
  • Command used:
    cfn-guard validate -r rule.guard -d template.json

  • Output:

Parsing error handling rules file = rule.guard, Error = Parser Error when parsing Parsing Error Error parsing file rule.guard at line 2 at column 1, when handling , fragment #EOF

---

Expected behavior
no error should be produced and cfn-guard should proceed with the validation.

Additional Context
I suspect that the error is caused due to the fact that the parser checks until it finds \n for comments which happens here

Operating System:
Ubuntu 20.04, Amazon Linux 2

@sepehrdaddev sepehrdaddev added the bug Something isn't working label Dec 29, 2021
joshfried-aws added a commit to joshfried-aws/cloudformation-guard that referenced this issue Sep 21, 2022
@joshfried-aws
Copy link
Contributor

Hi @sepehrdaddev we have merged a fix for this issue #278 . Feel free to test it out again, and re-open if you find anything more.

Thanks,

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

No branches or pull requests

3 participants