fix(cli): skip commented-out lines when resolving env vars in apisix.yaml#13686
Open
asdf2014 wants to merge 1 commit into
Open
fix(cli): skip commented-out lines when resolving env vars in apisix.yaml#13686asdf2014 wants to merge 1 commit into
asdf2014 wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Standalone mode fails to boot when
apisix.yamlcontains 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 withcan't find environment variable MY_ENV_VAR. (config.yamlis 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_linepredicate. 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#ENDmarker 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):
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;#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);${{...}}reference spanning a physical line no longer matches (all in-tree references are single-line);env VAR;nginx directive (comments having side effects was part of the bug).The new test in
t/cli/test_standalone.shcovers both paths:make init(CLI) andmake run+ request (runtime hot-reload) against a config whose commented-out lines reference unset vars.Which issue(s) this PR fixes:
Fixes #13685
Checklist