-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
Strip quotes from values #51
Comments
Hi @bostjan, thanks for the suggestion. I've thought about this, and decided I probably wouldn't accept a patch for simply stripping quotes. A couple of reasons:
>>> import configparser, io
>>> config = configparser.ConfigParser()
>>> config.read_file(io.StringIO('[section]\nquoted = "this is a test"\n'))
>>> config['section']['quoted']
'"this is a test"'
So I suggest simply stripping the quotes yourself in your own code/handler. For example, maybe something like this (though this is untested code!): // Strip " character from beginning and end of value -- doesn't handle escapes
if (value[0] == '"') {
value++;
if (value[0] && value[strlen(value) - 1] == '"') {
value[strlen(value) - 1] = '\0';
}
} |
Hey Ben, thanks for the answer and suggestion. I can live with a patch, which I already created in the mean time (handles single quotes too): Will review your code too, it is probably more elegant than mine (C is an occasional hobby for me). I anticipated the escaping part too, and I guess I will not go that far - KISS FTW. Feel free to close this issue at your leisure. |
Hi @bostjan Thanks -- note that you wouldn't have to patch ini.c, you could simply add the "quote skipping" code to the top of your user handler. I think the approach you're taking in your patch is reasonable, however, I don't understand why you have the same test in the first |
My use case for inih was to replace ndevilla/iniparser, which was doing very well until users reported segfaults under certain conditions, which I have no desire to investigate TBH. Patching ini.c is simpler in my case, as it does less code pollution in the original project (which assumed surrounding quotes would be removed already when previous library was used). But yes, agreed, your suggestion would work too. Will think about it, thanks. About else if: Example (I know, convoluted and stupid, but proves the point): |
Regarding the double quotes vs single quotes -- in that case I think you'll want to change the second one to look for the single quote character:
Closing this issue now. |
Aaaaah! And when I was working on that, I knew I had missed something and it was itching in my subconscious. Thanks! |
Hello,
I was just trying out your library and I have noticed that returned values include quotes if quotes exist in ini file, which is a tad annoying behavior for my use case.
I understand that to existing users this behavior might be expected and preferred.
I wonder if patch that creates new
-DSTRIP_VALUE_QUOTES
would be accepted and merged?Thanks for your consideration,
b.
The text was updated successfully, but these errors were encountered: