shini icon indicating copy to clipboard operation
shini copied to clipboard

shini_write unquotes previously quoted values

Open amtssp opened this issue 7 years ago • 8 comments

I think there is a bug within shini on how it handles quoted values. (Sorry I opened a new issue, as I didn't know if you would seem my comment in a closed thread).

If I have more than one quoted string shini will "unquote" previously quoted strings.

Code like this

SECTION_NAME=TEST
shini_write "shairportsync.cfg" "${SECTION_NAME}" "unquoted" "string"
shini_write "shairportsync.cfg" "${SECTION_NAME}" "quoted" "\"string\""
shini_write "shairportsync.cfg" "${SECTION_NAME}" "quoted2" "\"string2\""

Results in only the last quoted string to be quoted.

[TEST]
unquoted=string
quoted=string
quoted2="string2"

amtssp avatar Jun 06 '17 18:06 amtssp

When prioritizing the issues with shini - this one is for me the most severe problem. shini_write removes quotation marks from the ini file at random (at least I haven't figure out any system) when writing more than one key back to the ini file.

So - when you start working on shini again, please take a look at this one first.

amtssp avatar Jun 08 '17 18:06 amtssp

Hi Mathew. Sorry to disturb you, but have you had time to have a look at this issue?

amtssp avatar Jun 26 '17 13:06 amtssp

Sorry for the great delay, have had a lot going on personally.

I've located the bug, am working on a fix.

wallyhall avatar Jul 27 '17 07:07 wallyhall

This is tricky - because in a sense the current functionality is "correct".

unquoted=string
quoted="string"

As per the current reading rules in shini, these two values are identical. The double quotes on the second line are redundant. (See the documentation on the project homepage.)

Are you looking to have double quotes (like in the example above) returned as part of the value, rather than as quotes around the value?

wallyhall avatar Jul 27 '17 09:07 wallyhall

Thanks for looking into this.

For now I don't need double quotes as part of the value.

The reason for this bug-report was when discovered that if I used shini to write a quoted variable to an existing ini file - I noticed that it removed all existing double quotes (which were already present in the file) from this file and only left the actual double quotes that I was writing to the file.

Does this make sense?

amtssp avatar Jul 28 '17 13:07 amtssp

Yes it does.

I’m not certain though that the presence (or lack) of double quotes affects how the INI file is read by other software.

The “bug” is that shini currently doesn’t modify the one specific line in the file. Rather it re-generates the entire file from scratch, not bothering with double quotes.

I’ll have a look at modifying it to only alter the line in question, which might help improve write performance too.

On 28 Jul 2017, at 14:23, amtssp [email protected] wrote:

Thanks for looking into this.

For now I don't need double quotes as part of the value.

The reason for this bug-report was when discovered that if I used shini to write a quoted variable to an existing ini file - I noticed that it removed all existing double quotes (which were already present in the file) from this file and only left the actual double quotes that I was writing to the file.

Does this make sense?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/wallyhall/shini/issues/13#issuecomment-318650638, or mute the thread https://github.com/notifications/unsubscribe-auth/AEoMi_ApMQvAnyHjEXcECkQ-YFU1WqOqks5sSeDXgaJpZM4NxuWh.

wallyhall avatar Jul 28 '17 13:07 wallyhall

I see.

Yes - it is correct that I don't have problems if I use shini to read my file.
But sometime in our scripts we have used the "read" or " ." to source the ini file (probably we should change these old scripts).

However, if shini has removed the double quotes we are in trouble.

amtssp avatar Jul 28 '17 13:07 amtssp

OK I understand.

I’ll take a look tonight and this weekend.

On 28 Jul 2017, at 14:39, amtssp [email protected] wrote:

I see.

Yes - it is correct that I don't have problems if I use shini to read my file. But sometime in our scripts we have used the "read" or " ." to source the ini file (probably we should change these old scripts).

However, if shini has removed the double quotes we are in trouble.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/wallyhall/shini/issues/13#issuecomment-318654515, or mute the thread https://github.com/notifications/unsubscribe-auth/AEoMi7jKnQeobXsT12eCtGx8TiYCJ_kaks5sSeSsgaJpZM4NxuWh.

wallyhall avatar Jul 28 '17 14:07 wallyhall