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

config_to_str() doesn't quote default values correctly #195

Closed
ncihnegn opened this issue Jan 18, 2019 · 4 comments · Fixed by #198
Closed

config_to_str() doesn't quote default values correctly #195

ncihnegn opened this issue Jan 18, 2019 · 4 comments · Fixed by #198

Comments

@ncihnegn
Copy link
Contributor

Of course, the corresponding testcases are also missing.

If you can point out the direction, I will be happy to implement.

@henryiii
Copy link
Collaborator

Adding test cases and a correction would be great! I assume you are referring to the default Config output, the INI one. The ConfigINI class is in include/CLI/ConfigFwd.hpp, but the to_config part that you probably need is inside include/CLI/Config.hpp. Is there any quoting at all currently? I see << name << "=" << value << std::endl;, which I assume should actually have something like detail::add_quotes_if_needed(value) instead, and that new function would go into include/CLI/StringTools.hpp. Tests go in tests/IniTest.cpp.

@ncihnegn
Copy link
Contributor Author

Following your direction, I got something passing tests, but I am not sure it actually solves the problem. I will create a PR anyway.

Let me clarify:

  1. If there is a string whose default value with space inside, config_to_str() will not add quotes to it.
  2. If I use the output above as an INI file, parsing will fail.
  3. If I add quotes into the file, parsing will work.
  4. If I add quotes to all unquoted strings with space inside, it solves the parsing problem above.
  5. But the quotes added for vector values will fail some tests, because currently CLI11 assumes no quotes for vectors.

So is it actually an exporting problem or a parsing problem?
Now I really feel these are undefined behaviors of the INI format.
Will you consider adding TOML as the default?

@henryiii
Copy link
Collaborator

I'd be happy to have an example or auxiliary file to support TOML, but probably would not want to make it default. Anyone can add a new Config, and attach it to the main app. There's just an example for JSON currently.

The conversion to INI files was considered experimental, but it got promoted out of experimental status when the new customizable Config was added, maybe a bit too soon.

I'll think about vectors a bit and see what I can come up with. I think, however, if the current INI output can only support strings-with-spaces or vectors, the strings (this patch) would win as the more common issue.

@henryiii
Copy link
Collaborator

I've added a patch to make sure it does not quote vectors and merged. Thank you!

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 a pull request may close this issue.

2 participants