-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: remove trailing whitespace from awk command #913
Conversation
I don't think it's a proper fix since we can have multiple resolvers defined, and then if ORS is set to "" they will be squashed together, e.g. "127.0.0.1127.0.0.2". |
We probably just want to check if the latest character of the variable is whitespace and trim it |
Good point. Probably something like this then? |
I'd prefer a posix shell-compatible solution rather than another (costly) awk call - e.g. get the last character of a string, and then compare/trim |
Totally see your point. A. xargs NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf | xargs) B. shell expansion NGINX_LOCAL_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf)
NGINX_LOCAL_RESOLVERS="${NGINX_LOCAL_RESOLVERS%"${NGINX_LOCAL_RESOLVERS##*[![:space:]]}"}" |
76fdcf5
to
aa664ca
Compare
I think I've missed the last comment - sorry about that. Wouldnt the following simple patch work, as we're explicitely setting ORS to a space?
|
Trailing whitespaces break configs that use quotation marks around vars. See nginxinc/docker-nginx-unprivileged#234
I also thought about adding a test to catch issues like that, but more I look into, more I think it's a misconfiguration to put quotation marks in there, e.g.
|
aa664ca
to
ec81a15
Compare
No worries. Thanks for finalising it. I never used multiple resolvers yet, so I wasn't really aware of that test case. But yeah it's rather a misconfiguration and the trailing whitespace was only problematic for this edge case. Will update my config. ✌️ |
Proposed changes
Currently the awk command in
entrypoint/15-local-resolvers.envsh
will always produce a trailing whitespace.This will break configs that make use of quotation marks around variable in config templates.
Initially opened the issue here: nginxinc/docker-nginx-unprivileged#234
Checklist
Before creating a PR, run through this checklist and mark each as complete:
CONTRIBUTING
document./update.sh
and ensured all entrypoint/Dockerfile template changes have been applied to the relevant image entrypoint scripts & Dockerfiles