https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-07-06T10:10:58ZRuby Issue Tracking SystemRuby master - Bug #13722: OptionParser::DecimalInteger can be converted as Octalhttps://bugs.ruby-lang.org/issues/13722?journal_id=656522017-07-06T10:10:58Zwmccumstie (William McCumstie)
<ul></ul><p>A PR containing a bug fix can be found at:<br>
<a href="https://github.com/ruby/ruby/pull/1665" class="external">https://github.com/ruby/ruby/pull/1665</a></p> Ruby master - Bug #13722: OptionParser::DecimalInteger can be converted as Octalhttps://bugs.ruby-lang.org/issues/13722?journal_id=656532017-07-06T10:19:35Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>I wonder if this is a bug or an intended behaviour.</p> Ruby master - Bug #13722: OptionParser::DecimalInteger can be converted as Octalhttps://bugs.ruby-lang.org/issues/13722?journal_id=656542017-07-06T10:48:21Zmjtko (Mark Titorenko)nospam-rubylang.org@titorenko.net
<ul></ul><p>shyouhei (Shyouhei Urabe) wrote:</p>
<blockquote>
<p>I wonder if this is a bug or an intended behaviour.</p>
</blockquote>
<p>I would argue that this is a bug. The test here -- <a href="https://github.com/ruby/ruby/blob/trunk/test/optparse/test_acceptable.rb#L115" class="external">https://github.com/ruby/ruby/blob/trunk/test/optparse/test_acceptable.rb#L115</a> -- also doesn't feel correct, as it's testing that <code>09</code> generates an <code>OptionParser::InvalidArgument</code> exception, though that only happens because <code>09</code> is not valid octal.</p>
<p>If the intention is for <code>OptionParser:DecimalInteger</code> to behave the same as <code>Integer</code> but disallow hex and binary values, then perhaps it would be better called <code>OptionParser::OctalOrDecimalInteger</code>. :-) As there is already a specific type <code>OptionParser::OctalInteger</code>, it suggests to me that <code>OptionParser::DecimalInteger</code> should be generating base-10 output only; generating base-8 output is confusing and, for me at least, violates the principle of least surprise.</p> Ruby master - Bug #13722: OptionParser::DecimalInteger can be converted as Octalhttps://bugs.ruby-lang.org/issues/13722?journal_id=656552017-07-06T10:56:27Zwmccumstie (William McCumstie)
<ul></ul><p>I don't believe it would be intended behaviour. At very least it would be strange to specifically specify a Decimal only to have it converted as Octal.</p>
<p>Looking into to the unit tests (test/optparse/test_acceptable.rb:115), I would have expected the intended behaviour to raise OptionParser::InvalidArgument if anything.</p> Ruby master - Bug #13722: OptionParser::DecimalInteger can be converted as Octalhttps://bugs.ruby-lang.org/issues/13722?journal_id=656562017-07-06T11:10:38Zwmccumstie (William McCumstie)
<ul></ul><p>From optparse.rb:</p>
<pre><code>OptionParser comes with a few ready-to-use kinds of type
# coercion. They are:
#
# - Date -- Anything accepted by +Date.parse+
# - DateTime -- Anything accepted by +DateTime.parse+
# - Time -- Anything accepted by +Time.httpdate+ or +Time.parse+
# - URI -- Anything accepted by +URI.parse+
# - Shellwords -- Anything accepted by +Shellwords.shellwords+
# - String -- Any non-empty string
# - Integer -- Any integer. Will convert octal. (e.g. 124, -3, 040)
# - Float -- Any float. (e.g. 10, 3.14, -100E+13)
# - Numeric -- Any integer, float, or rational (1, 3.4, 1/3)
# - DecimalInteger -- Like +Integer+, but no octal format.
# - OctalInteger -- Like +Integer+, but no decimal format.
# - DecimalNumeric -- Decimal integer or float.
# - TrueClass -- Accepts '+, yes, true, -, no, false' and
# defaults as +true+
# - FalseClass -- Same as +TrueClass+, but defaults to +false+
# - Array -- Strings separated by ',' (e.g. 1,2,3)
# - Regexp -- Regular expressions. Also includes options.
</code></pre>
<p>DecimalInteger does not support octal format. So either it should convert as a decimal or throw an error.</p> Ruby master - Bug #13722: OptionParser::DecimalInteger can be converted as Octalhttps://bugs.ruby-lang.org/issues/13722?journal_id=656572017-07-06T11:49:10Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r59273.</p>
<hr>
<p>Fix DecimalInteger converting to octal bug</p>
<p>Previously if the input started with a '0' then it will be converted<br>
as octal even though it has been specified as a decimal. This commit<br>
forces the number to be interpreted as a decimal.</p>
<p><a href="/issues/13722">[ruby-core:81927]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: OptionParser::DecimalInteger can be converted as Octal (Closed)" href="https://bugs.ruby-lang.org/issues/13722">#13722</a>] [Fix GH-1665]<br>
Author: william <a href="mailto:william.mccumstie@outlook.com" class="email">william.mccumstie@outlook.com</a></p> Ruby master - Bug #13722: OptionParser::DecimalInteger can be converted as Octalhttps://bugs.ruby-lang.org/issues/13722?journal_id=656582017-07-06T11:55:12Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/65658/diff?detail_id=45537">diff</a>)</li></ul><p>Thank you, it's obviously a bug.</p>