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

.INI can't parse newlines #139

Open
FrostBird347 opened this issue Jul 13, 2022 · 2 comments
Open

.INI can't parse newlines #139

FrostBird347 opened this issue Jul 13, 2022 · 2 comments

Comments

@FrostBird347
Copy link

Attempting to load a string containing "\n" will not produce a string containing a newline.

For example:

[Naming]
OldText=Test0
Text=Test1\nTest2
Mode=0

Will read Naming.Text as "Test1\nTest2" instead of

"Test1
Test2"

(which I will be referring to as "Test1␤Test2" from now on)

In addition, attempting to save the string "Test1␤Test2" to Naming.Text will produce this file:

[Naming]
OldText=Test0
Text=Test1
Test2
Mode=0

Not only will any subsequent attempt at reading the value of Naming.Text only return the first line, changing the new string from "Test1␤Test2" to "Test1␤OldText=Test2" will make all subsequent attempts at reading the value of Naming.OldText return "Test2", as long as Naming.Text was stored below Naming.OldText

@aloneguid aloneguid added help needed Feel free to grab the issue and work on it. up for grabs and removed help needed Feel free to grab the issue and work on it. labels Jul 28, 2022
@JamesBondski
Copy link
Contributor

I would like to try my hands at this..

In the end, adding a "wrong" (=not supported) value to an ini file should not end up corrupting the file. All I'd do would be to make sure that \r and \n are translated to the appropriate characters in the string and upon writing are translated back and add test cases for both reading and writing.

Does that sound alright? I quite like that the library is pretty robust when parsing ini files otherwise, even allowing stuff like ; and = inside of values with some limits. If wanted, support for the more escape characters would be easy to do (https://en.wikipedia.org/wiki/INI_file#Escape_characters).

@aloneguid
Copy link
Owner

@JamesBondski supporting =, #, etc after first = is great as today I can just paste base64 encoded value into .ini. Basically I can paste anything without worrying about escaping, however as you have noticed newline will break the parser, because it treats each line as a separate entity. I'd suggest escaping anything that can break the line, in both key and value. Please go ahead if you like to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants