Skip to content

cqfd: do not remove whitespaces around assignment#152

Open
gportay wants to merge 1 commit intosavoirfairelinux:masterfrom
gportay:stop-removing-whitespaces-around-equal
Open

cqfd: do not remove whitespaces around assignment#152
gportay wants to merge 1 commit intosavoirfairelinux:masterfrom
gportay:stop-removing-whitespaces-around-equal

Conversation

@gportay
Copy link
Copy Markdown
Contributor

@gportay gportay commented Feb 17, 2025

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 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,

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

@gportay
Copy link
Copy Markdown
Contributor Author

gportay commented Feb 17, 2025

In the same series of #141.

@florentsfl florentsfl force-pushed the stop-removing-whitespaces-around-equal branch from 8c5b33c to 844ae3b Compare February 17, 2025 21:20
@gportay
Copy link
Copy Markdown
Contributor Author

gportay commented Feb 17, 2025

For now, this PR should not be merged until it has been decided what is the way to go with breaking changes (see comment).

@florentsfl florentsfl added this to the v6.0 milestone Jun 25, 2025
@gportay gportay force-pushed the stop-removing-whitespaces-around-equal branch from 844ae3b to 0ade038 Compare June 26, 2025 20:33
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/
@gportay gportay force-pushed the stop-removing-whitespaces-around-equal branch from 0ade038 to 8cae89d Compare July 8, 2025 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants