Skip to content

Map analyzer rejects special parameter names used as map keys #176

Description

@wow220809

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

  1. Use nginx-go-crossplane v0.4.89 or main commit:
11d0d6bebfebff2fd79062e5a4ff7afd418dcc36
  1. Create nginx.conf:
events {}

http {
    map $source $result {
        volatile true;
        hostnames enabled;
    }
}
  1. 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)
}
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions