cqfd: do not remove whitespaces around assignment#152
Open
gportay wants to merge 1 commit intosavoirfairelinux:masterfrom
Open
cqfd: do not remove whitespaces around assignment#152gportay wants to merge 1 commit intosavoirfairelinux:masterfrom
gportay wants to merge 1 commit intosavoirfairelinux:masterfrom
Conversation
Contributor
Author
|
In the same series of #141. |
8c5b33c to
844ae3b
Compare
Contributor
Author
|
For now, this PR should not be merged until it has been decided what is the way to go with breaking changes (see comment). |
844ae3b to
0ade038
Compare
Both .ini and shell grammars use the equal sign for assignment (=). The sign delimitates the property and the variable name from their value. Whitespaces on both side of the sign are allowed in the .ini world while they are not in the shell grammar. Here is a property statement in an .ini file: property = value And, a variable assigment in shell: variable=value The hacky parser[1] transforms an .ini file into a shell script: a section is a shell function, and a property is a variable. As a consequence, the parser must ensure to remove the whitespaces wrapping the sign = if any. It uses a shell substitution to strip off the whitespaces on both side of the **first occurence** of the equal sign. Unfortunatly, the parser is not smart enough to make the disctinction if the **first occurence** of the equal with surrounding whitespaces is the sign delimitating the property and its value or if it is part of the value. Therefore, it may result in stripping off the whitespaces in the value if there is no whitespaces arround the assigment sign as in the example below. The following command property, command='if test "$container" = "podman"; then echo podman; else exit 1; fi' Become the command variable: command='if test "$container"="podman"; then echo podman; else exit 1; fi' And the command always evaluates to true as the expression is a single string "$container"='podman' (evaluated to =podman) that is a non-null expression and thus true as per test(1): test EXPRESSION The parser needs to strip An omitted EXPRESSION defaults to false. Otherwise, EXPRESSION is true or false and sets exit status. See: gportay@archlinux ~ $ test "$container"="'podman' && echo okay okay This stops to strip off the whitespaces to avoid altering the variable values if the .cqfdrc does not use spaces around the equal sign. Note: This is workaround as: command = 'if test "$container" = "podman"; then echo podman; else Or as: command='if test "$container" = "podman"; then echo podman; else [1]: https://ajdiaz.wordpress.com/2008/02/09/bash-ini-parser/
0ade038 to
8cae89d
Compare
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.
Both .ini and shell grammars use the equal sign for assignment (=). The sign delimitates the property and the variable name from their value.
Whitespaces on both side of the sign are allowed in the .ini world while they are not in the shell grammar.
Here is a property statement in an .ini file:
And, a variable assigment in shell:
The hacky parser1 transforms an .ini file into a shell script: a section is a shell function, and a property is a variable.
As a consequence, the parser must ensure to remove the whitespaces wrapping the sign = if any. It uses a shell substitution to strip off the whitespaces on both side of the first occurence of the equal sign.
Unfortunatly, the parser is not smart enough to make the disctinction if the first occurence of the equal with surrounding whitespaces is the sign delimitating the property and its value or if it is part of the value.
Therefore, it may result in stripping off the whitespaces in the value if there is no whitespaces arround the assigment sign as in the example below.
The following command property,
exit 1; fi'
Become the command variable:
exit 1; fi'
And the command always evaluates to true as the expression is a single string "$container"='podman' (evaluated to =podman) that is a non-null expression and thus true as per test(1):
See:
This stops to strip off the whitespaces to avoid altering the variable values if the .cqfdrc does not use spaces around the equal sign.
Note: This is workaround as:
Or as: