Skip to content
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

Properly quote replacment string in param expansion #146

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

baodrate
Copy link
Contributor

Improper quoting causes the replacement string in the log format to be mangled. Specifically, instances of & in a log message will be replaced with the replacement pattern in the log format (namely: {MESSAGE}).

For example:

bashio::log.info "FOO&BAR&BAZ"

produces:

[08:17:56] INFO: FOO{MESSAGE}BAR{MESSAGE}BAZ

although one would expect it to produce:

[08:17:56] INFO: FOO&BAR&BAZ

This PR quotes the replacement strings so that the & character is treated as a literal character by bash.


From the bash manual:

If the patsub_replacement shell option is enabled using shopt, any unquoted instances of ‘&’ in string are replaced with the matching portion of pattern. This is intended to duplicate a common sed idiom.

Quoting any part of string inhibits replacement in the expansion of the quoted portion, including replacement strings stored in shell variables. Backslash will escape ‘&’ in string; the backslash is removed in order to permit a literal ‘&’ in the replacement string. Users should take care if string is double-quoted to avoid unwanted interactions between the backslash and double-quoting, since backslash has special meaning within double quotes. Pattern substitution performs the check for unquoted ‘&’ after expanding string, so users should ensure to properly quote any occurrences of ‘&’ they want to be taken literally in the replacement and ensure any instances of ‘&’ they want to be replaced are unquoted.

@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementors. label Dec 7, 2023
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @baod-rate 👍

../Frenck

@frenck frenck merged commit 2de0c23 into hassio-addons:main Dec 7, 2023
4 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix Inconsistencies or issues which will cause a problem for users or implementors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants