Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-9303

A heredoc with interpolation containing [ ] in the expression can cause syntax error

    XMLWordPrintable

Details

    • Froyo
    • Needs Assessment
    • Bug Fix
    • Hide
      Heredoc expressions with interpolation using an access expression like `$facts['somefact']` could fail with a syntax error depending on the relative location in the source file of the heredoc and surrounding whitespace (anywhere) in the source file. This was caused by a faulty calculation of location of interpolated expressions which also showed up as the wrong line/position in error messages related to the interpolated expressions.

      The handling of the position of so called "sublocated expressions" is now rewritten and the problem with seemingly random "syntax error" from the use of `[]` expression in interpolation is gone.

      Advanced: Anyone having written tools that walk the AST tree should note that the `SublocatedExpression` will no longer be generated by the parser as all nodes under that node are now immediately updated with their correct offset and length. Although the `SublocatedExpression` class itself will not be removed until Puppet 7.0.0, it will no longer appear in AST produced by the parser.
      Show
      Heredoc expressions with interpolation using an access expression like `$facts['somefact']` could fail with a syntax error depending on the relative location in the source file of the heredoc and surrounding whitespace (anywhere) in the source file. This was caused by a faulty calculation of location of interpolated expressions which also showed up as the wrong line/position in error messages related to the interpolated expressions. The handling of the position of so called "sublocated expressions" is now rewritten and the problem with seemingly random "syntax error" from the use of `[]` expression in interpolation is gone. Advanced: Anyone having written tools that walk the AST tree should note that the `SublocatedExpression` will no longer be generated by the parser as all nodes under that node are now immediately updated with their correct offset and length. Although the `SublocatedExpression` class itself will not be removed until Puppet 7.0.0, it will no longer appear in AST produced by the parser.
    • Needs Assessment

    Description

      Puppet Version: Anything greater than 5.X
      Puppet Server Version: N/A
      OS Name/Version: N/A

      Download the simp_pki_service module from https://github.com/simp/pupmod-simp-simp_pki_service and run puppet parser validate manifests/kra.pp.

      Use d07265e253bb2cb11314dbb962043a21a2cbad05 for the breaking behavior. Changing the fact call to a local variable did not show any issues.

      Desired Behavior:

      No validation errors should be shown (just as in Puppet 4)

      Actual Behavior:

      Puppet parser validation fails with a syntax error in the HEREDOC at line 123.

      Note: Removing the only line in the comments section of the document causes the validation to no longer fail.

      UPDATE
      ------
      This is the same problem as in PUP-9163 which apparently did not fix all cases of the problem.

      The issue is that the lexer looks at the wrong character when it is looking at what comes just before the [ char in an interpolated expression inside a heredoc. The position it is looking at depend on how much source text there is before the [ - if the erroneous position happens to be a space the result is a syntax error.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              peiriannydd Trevor Vaughan
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support