Describe the bug
The map body analyzer always treats volatile and hostnames as
special no-argument parameters based only on their names.
NGINX distinguishes special parameters from ordinary map entries using
both the parameter name and the number of arguments. In NGINX,
volatile and hostnames are treated as special parameters only when
they appear without a value.
When either token is followed by one value, NGINX continues through the
ordinary map key/value path. For example:
volatile true;
hostnames enabled;
These statements represent ordinary map entries:
key=volatile, value=true
key=hostnames, value=enabled
nginx-go-crossplane currently applies the no-argument mask immediately
after matching the token name. It therefore reports
invalid number of parameters instead of falling back to the ordinary
map-entry argument rules.
This causes configurations accepted by the NGINX parser to be reported
as parse failures. Downstream tools may consequently treat otherwise
analyzable NGINX configurations as incomplete.
To reproduce
- Use nginx-go-crossplane v0.4.89 or main commit:
11d0d6bebfebff2fd79062e5a4ff7afd418dcc36
- Create
nginx.conf:
events {}
http {
map $source $result {
volatile true;
hostnames enabled;
}
}
- Parse it with the following program:
package main
import (
"fmt"
crossplane "github.com/nginxinc/nginx-go-crossplane"
)
func main() {
payload, err := crossplane.Parse(
"nginx.conf",
&crossplane.ParseOptions{
SingleFile: true,
},
)
if err != nil {
fmt.Printf("parse error: %v\n", err)
}
fmt.Printf("payload errors: %+v\n", payload.Errors)
}
- Observe that
payload.Errors contains map parse errors with:
invalid number of parameters
The errors are produced for volatile true; and
hostnames enabled;.
Expected behavior
The map analyzer should follow the same arity-based distinction as the
NGINX configuration parser:
volatile; should be treated as the special parameter that marks the
resulting variable as non-cacheable.
hostnames; should be treated as the special parameter that enables
hostname matching.
volatile true; should be treated as an ordinary map entry with the
key volatile and the value true.
hostnames enabled; should be treated as an ordinary map entry with
the key hostnames and the value enabled.
- A map entry with more than one value should remain invalid.
When a token matches a special parameter name but does not satisfy the
special parameter's argument mask, the analyzer should try the default
map-entry argument mask before reporting an error.
Your environment
- nginx-go-crossplane version: v0.4.89
- nginx-go-crossplane commit:
11d0d6bebfebff2fd79062e5a4ff7afd418dcc36
- Target deployment platform: platform-independent Go library parser
Describe the bug
The map body analyzer always treats
volatileandhostnamesasspecial no-argument parameters based only on their names.
NGINX distinguishes special parameters from ordinary map entries using
both the parameter name and the number of arguments. In NGINX,
volatileandhostnamesare treated as special parameters only whenthey appear without a value.
When either token is followed by one value, NGINX continues through the
ordinary map key/value path. For example:
These statements represent ordinary map entries:
nginx-go-crossplane currently applies the no-argument mask immediately
after matching the token name. It therefore reports
invalid number of parametersinstead of falling back to the ordinarymap-entry argument rules.
This causes configurations accepted by the NGINX parser to be reported
as parse failures. Downstream tools may consequently treat otherwise
analyzable NGINX configurations as incomplete.
To reproduce
nginx.conf:payload.Errorscontains map parse errors with:The errors are produced for
volatile true;andhostnames enabled;.Expected behavior
The map analyzer should follow the same arity-based distinction as the
NGINX configuration parser:
volatile;should be treated as the special parameter that marks theresulting variable as non-cacheable.
hostnames;should be treated as the special parameter that enableshostname matching.
volatile true;should be treated as an ordinary map entry with thekey
volatileand the valuetrue.hostnames enabled;should be treated as an ordinary map entry withthe key
hostnamesand the valueenabled.When a token matches a special parameter name but does not satisfy the
special parameter's argument mask, the analyzer should try the default
map-entry argument mask before reporting an error.
Your environment
11d0d6bebfebff2fd79062e5a4ff7afd418dcc36