Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#2727 closed Bugs (fixed)

program_options ill behaviour with unrecognized options

Reported by: sebastian.weber@… Owned by: Sascha Ochsenknecht
Milestone: Boost 1.42.0 Component: program_options
Version: Boost 1.37.0 Severity: Problem
Keywords: Cc: dcnieho@…

Description

Hi!

There is an inconsistency in the handling of unrecognized tokens when parsing config-files. The function collect_unrecognized will never return the unknown options, since it just copies of the original_token field which is left empty from the config file parser in contrast to the cmd line parser.

Greetings,

Sebastian Weber

Change History (4)

comment:1 by Diederick C. Niehorster <dcnieho@…>, 13 years ago

Cc: dcnieho@… added

Yeah, there must be a cool reason why the original_token field is outputted as the unrecognized options, but i think instead we could simply output the string_key, which is set for all (registered and unregistered) options. if mode == include_positional && options[i].position_key != -1, add the value for that entry to the output vector. That should do the trick.

proposed diff:

Index: parsers.hpp
===================================================================
--- parsers.hpp (revision 54915)
+++ parsers.hpp (working copy)
@@ -129,13 +129,12 @@
         std::vector< std::basic_string<charT> >  result;
         for(unsigned i = 0; i < options.size(); ++i)
         {
-            if (options[i].unregistered ||
-                (mode == include_positional && options[i].position_key != -1))
-            {
-                copy(options[i].original_tokens.begin(),
-                     options[i].original_tokens.end(),
+            if (options[i].unregistered)
+                result.push_back(options[i].string_key);
+            else if (mode == include_positional && options[i].position_key != -
1)
+                copy(options[i].value.begin(),
+                     options[i].value.end(),
                      back_inserter(result));
-            }
         }
         return result;
     }

comment:2 by Sascha Ochsenknecht, 13 years ago

Milestone: Boost 1.38.0Boost 1.42.0
Owner: changed from Vladimir Prus to Sascha Ochsenknecht
Status: newassigned

The 'cool' reason is that original_tokens are original :-), i.e. they are stored untouched like they appeared on cmdline/config file. The purpose of collect_unrecognized() is to return them and the user can pass them to an own parser implementation.

comment:3 by Sascha Ochsenknecht, 13 years ago

Resolution: fixed
Status: assignedclosed

(In [58233]) config file parser now stores original_tokens, Fixes #2727

comment:4 by Sascha Ochsenknecht, 13 years ago

I just checked it a patch which uses a different approach than the above proposal. I decided to store the original_tokens when parsing the config file and keep the collect function untouched.

Note: See TracTickets for help on using tickets.