asdf2014 opened a new pull request, #13686:
URL: https://github.com/apache/apisix/pull/13686

   ### Description
   
   Standalone mode fails to boot when `apisix.yaml` contains a commented-out 
env var reference:
   
   ```yaml
   # ${{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
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [x] I have verified that this change is backward compatible (If not, 
please discuss on the [APISIX mailing 
list](https://github.com/apache/apisix/tree/master#community) first)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to