Skip to content

fix(cli): skip commented-out lines when resolving env vars in apisix.yaml#13686

Open
asdf2014 wants to merge 1 commit into
apache:masterfrom
asdf2014:fix-standalone-commented-env-var
Open

fix(cli): skip commented-out lines when resolving env vars in apisix.yaml#13686
asdf2014 wants to merge 1 commit into
apache:masterfrom
asdf2014:fix-standalone-commented-env-var

Conversation

@asdf2014

@asdf2014 asdf2014 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Description

Standalone mode fails to boot when apisix.yaml contains a commented-out env var reference:

# ${{MY_ENV_VAR}}

Since #13078 (shipped in 3.17.0), ${{VAR}} is substituted on the raw text before YAML parsing so the parser can infer scalar types — which means comment lines are substituted too, and an unset var inside a comment aborts startup with can't find environment variable MY_ENV_VAR. (config.yaml is unaffected: it substitutes on the parsed table where comments are already gone; same for JSON standalone configs, which also resolve post-parse.)

This patch makes the raw-text substitution run line by line, keeping full-line comments (and blank / no-reference lines) verbatim, reusing the existing is_empty_yaml_line predicate. A leading UTF-8 BOM is detached first so a first-line comment is still recognized. Unset vars on data lines still fail with the same error message; output is byte-identical to the previous implementation for comment-free input (line endings, missing trailing newline, and the #END marker are all preserved). Both callers — CLI init (cli/file.lua) and the runtime hot-reload (core/config_yaml.lua) — share the fixed function.

Behavior notes (accepted trade-offs of the text-level heuristic, documented in the code comment):

  • inline trailing comments (key: val # ${{VAR}}) are still substituted — # may legally appear inside YAML strings, and telling those apart requires a full parse, which can only happen after substitution;
  • a block-scalar content line that itself starts with # is now skipped like a comment (no in-tree config or doc example hits this; the failure mode is a visible literal ${{VAR}}, not a crash);
  • a ${{...}} reference spanning a physical line no longer matches (all in-tree references are single-line);
  • a var referenced only in a comment no longer emits an env VAR; nginx directive (comments having side effects was part of the bug).

The new test in t/cli/test_standalone.sh covers both paths: make init (CLI) and make run + request (runtime hot-reload) against a config whose commented-out lines reference unset vars.

Which issue(s) this PR fixes:

Fixes #13685

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

…yaml

Since apache#13078 (3.17.0), env vars in apisix.yaml are substituted on the
raw text before YAML parsing, so a commented-out `# ${{VAR}}` aborted
startup when VAR was unset.

Substitute line by line and keep comment / blank / no-reference lines
verbatim (reusing is_empty_yaml_line); detach a leading UTF-8 BOM so a
first-line comment is still recognized. Both the CLI init path and the
runtime hot-reload path share the fixed function.

Fixes apache#13685
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: commented out env variables cause app to fail to boot

1 participant