Jira (PUP-11813) Parenthesized expression causes EPP template validation failures

12 views
Skip to first unread message

Torbjörn Lönnemark

unread,
Apr 6, 2023, 1:37:02 PM4/6/23
to puppe...@googlegroups.com
Torbjörn Lönnemark created an issue
 
Puppet / Bug PUP-11813
Parenthesized expression causes EPP template validation failures
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2023/04/06 10:36 AM
Priority: Normal Normal
Reporter: Torbjörn Lönnemark

Puppet Version: 7.23.0

The following EPP template:

# any content
<% ([1, 2, 3] + [7, 8, 9]).each |$x| { -%>
<%= $x %>
<% } -%>

fails validation with:

$ puppet epp validate test.pp
Error: Ambiguous EPP parameter expression. Probably missing '<%-' before parameters to remove leading whitespace (file: test.pp, line: 1, column: 1)

Even with a parameter tag present (i.e. <%- || -%> prepended to the file), validation still fails with the same error.

I would expect the template to pass validation (both with and without a parameter tag).

As far as I can tell the parenthesized expression is what triggers it. Here's a more minimal (but less realistic) example, which I would expect to fail validation with "This Parenthesized Expression has no effect", but that fails with "Ambiguous EPP parameter expression":

# any content
<% (1) %>

While writing this report, I also found that having two of these (parenthesized).each constructs in sequence:

<% ([1, 2, 3] + [7, 8, 9]).each |$x| { -%>
<%= $x %>
<% } -%>
<% ([1, 2, 3] + [7, 8, 9]).each |$x| { -%>
<%= $x %>
<% } -%>

fails with a different validation error:

$ puppet epp validate test2.epp
Error: Illegal expression. A Method call is unacceptable as function name in a Function Call (file: test2.epp, line: 1, column: 27)

while I would expect validation to pass.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Josh Cooper (Jira)

unread,
Apr 11, 2023, 4:30:03 PM4/11/23
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11813
 
Re: Parenthesized expression causes EPP template validation failures

Torbjörn Lönnemark thanks for letting us know. Note the leading comment is causing validation to fail. If you remove # any content then epp validation succeeds:

~/work/puppet 7.x*
❯ cat  epp.pp  
<% ([1, 2, 3] + [7, 8, 9]).each |$x| { -%>
<%= $x %>
<% } -%>
 
~/work/puppet 7.x*
❯ bx puppet epp validate epp.pp
 
~/work/puppet 7.x*
❯ echo $?
0

Similary, if you remove the comment from:

<% (1) %>

❯ bx puppet epp validate epp.pp
Error: This Parenthesized Expression has no effect. A value was produced and then forgotten (one or more preceding expressions may have the wrong form) (file: epp.pp, line: 1, column: 4)

Unless I'm missing something, I think this can be closed?

Torbjörn Lönnemark

unread,
Apr 12, 2023, 11:33:03 AM4/12/23
to puppe...@googlegroups.com

Presence of preceeding content is what triggers it, but I would expect code like this to work anywhere within a template file.

When you generate e.g. a configuration file using a template you will usually have some content before and after any embedded Puppet code. For example, this works:

[main]
config_option1 = true
config_option2 = <%= $param %>
config_option3 = false

Now, if we want to emit multiple lines based on the result of an expression (which needs to be parenthesized so we can call each on it):

[main]
config_option1 = true
<% ([4] + [7, 8, 9]).each |$x| { -%>
config_option_<%= $x %> = false
<% } -%>
config_option3 = false

(the values used in the expression within parentheses would commonly be template parameters, but here they're hardcoded for demonstration purposes)

This code will also fail validation with "Ambiguous EPP parameter expression", and in this case we can't just remove the preceding content.

I would have expected such a use of a parenthesized expression to work, regardless of whether it's located at the start of the file.

Tony Vu (Jira)

unread,
Apr 18, 2023, 4:33:02 PM4/18/23
to puppe...@googlegroups.com
Tony Vu updated an issue
 
Change By: Tony Vu
Labels: needs-validation

Henrik Lindberg (Jira)

unread,
May 15, 2023, 5:22:03 AM5/15/23
to puppe...@googlegroups.com
Henrik Lindberg commented on Bug PUP-11813
 
Re: Parenthesized expression causes EPP template validation failures

The validation and transformation of the AST that comes back from the parser is probably where the problem is. It may naively look for "Something followed by parentheses" and it finds TEXT PARENTHESIZED_EXPRESSION. It should just let that pass as it cannot possibly be the start of a parameterized EPP.

Reply all
Reply to author
Forward
0 new messages