Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-10-04T13:21:59ZRuby Issue Tracking System
Redmine Ruby master - Bug #16238 (Closed): Publish new WEBrick version to rubygems.orghttps://bugs.ruby-lang.org/issues/162382019-10-04T13:21:59Zrbjl (Jan Lelis)hi@ruby.consulting
<p>The latest security releases of Ruby include some fixes in the webrick default gem:</p>
<ul>
<li><a href="https://www.ruby-lang.org/en/news/2019/10/01/webrick-regexp-digestauth-dos-cve-2019-16201/" class="external">https://www.ruby-lang.org/en/news/2019/10/01/webrick-regexp-digestauth-dos-cve-2019-16201/</a></li>
<li><a href="https://www.ruby-lang.org/en/news/2019/10/01/http-response-splitting-in-webrick-cve-2019-16254/" class="external">https://www.ruby-lang.org/en/news/2019/10/01/http-response-splitting-in-webrick-cve-2019-16254/</a></li>
</ul>
<p>However, as of now, the changes have not been published to rubygems:</p>
<ul>
<li><a href="https://rubygems.org/gems/webrick" class="external">https://rubygems.org/gems/webrick</a></li>
</ul>
<p>More confusingly, the version number of webrick has not be changed yet: <a href="https://github.com/ruby/ruby/blob/v2_6_5/lib/webrick/version.rb" class="external">https://github.com/ruby/ruby/blob/v2_6_5/lib/webrick/version.rb</a> (still 1.4.2 as before the security patches). This is problematic, because now multiple versions of version 1.4.2 of webrick exist... It also prevents people from quickly resolving the webrick-related security issue by just installing the new version of webrick.</p>
<p>In the past, security patches often led to a fourth-place-version-number (see for example, rubygems itself, or <a href="https://github.com/ruby/ruby/commit/8c57255f87e2a70a033d9b1e2bdd474bc1ba6cc5" class="external">rdoc</a>)</p>
<p>I suggest that a new version of webrick should be released to rubygems. I am also curious about how the process of dealing with similar issues in the future can be optimized</p> Ruby master - Feature #15781 (Open): Unify Method List Introspection?https://bugs.ruby-lang.org/issues/157812019-04-21T20:43:58Zrbjl (Jan Lelis)hi@ruby.consulting
<p>Although Ruby has many core methods for retrieving the list of methods available to an object, or to the instances of a class, I believe they have gotten a little confusing (<a href="https://idiosyncratic-ruby.com/25-meta-methodology.html" class="external">also see</a>):</p>
<ul>
<li>
<code>Object#methods</code> and <code>Module#instance_methods</code> do not include <strong>private</strong> methods (at the same time they do include <strong>protected</strong> ones). There is already <code>Object#public_methods</code> (and <code>Object#protected_methods</code>) for distinguishing visibility scope , but no way to get <em>all</em> methods of an object.</li>
<li>There is the inconsistency that in most cases the argument being passed to <code>*_methods</code> methods let's you decide if you want to consider the inheritance chain, or not - But the prominent exception is <code>Object#methods</code> which instead toggles inheritance to singleton only! (for which we also have <code>Object#singleton_methods</code>)</li>
<li>There is no direct API for getting a list of private singleton methods</li>
</ul>
<p>Now that we have keyword arguments, we could provide a single API for listing methods. One way of doing so could be the <a href="https://github.com/janlelis/object_shadow#method-introspection" class="external">Object#shadow's methods method</a>. Having a keyword arguments based API would allow users to specify the dimensions of their requests better - should it:</p>
<ul>
<li>return the object's methods, or methods of its instances?</li>
<li>return only methods of a specific visibility scope?</li>
<li>return only methods of a specific inheritance level (e.g. only singleton, or all the way down to <code>BasicObject</code>)?</li>
</ul>
<p>What do you think about having one unified way for retrieving an object's method list?</p> Ruby master - Feature #14055 (Rejected): String#casecmp should use Unicode foldinghttps://bugs.ruby-lang.org/issues/140552017-10-25T17:42:27Zrbjl (Jan Lelis)hi@ruby.consulting
<p>The following string and symbol methods are currently only ASCII aware:</p>
<ul>
<li>String#casecmp</li>
<li>String#casecmp!</li>
<li>Symbol#casecmp</li>
<li>Symbol#casecmp!</li>
</ul>
<p>For example:</p>
<pre><code>"a".casecmp("A") #=> 0
"ä".casecmp("Ä") #=> 1
</code></pre>
<p>Now that Ruby has implemented case-folding (which is meant for comparing strings, see <a href="http://unicode.org/faq/casemap_charprop.html#2" class="external">http://unicode.org/faq/casemap_charprop.html#2</a>), it should be used when doing a casecmp on Unicode strings:</p>
<pre><code>"Ä".downcase(:fold) == "ä" #=> true
</code></pre> Ruby master - Feature #13780 (Closed): String#each_graphemehttps://bugs.ruby-lang.org/issues/137802017-08-03T18:35:07Zrbjl (Jan Lelis)hi@ruby.consulting
<p>Ruby's regex engine has support for graphemes via <code>\X</code>:</p>
<p><a href="https://github.com/k-takata/Onigmo/blob/791140951eefcf17db4e762e789eb046ea8a114c/doc/RE#L117-L124" class="external">https://github.com/k-takata/Onigmo/blob/791140951eefcf17db4e762e789eb046ea8a114c/doc/RE#L117-L124</a></p>
<p>This is really useful when working with Unicode strings. However, code like <code>string.scan(/\X/)</code> is not so readable enough, which might lead people to use String#each_char, when they really should split by graphemes.</p>
<p>What I propose is two new methods:</p>
<ul>
<li>String#each_grapheme which returns an Enumerator of graphemes (in the same way like <code>\X</code>)</li>
</ul>
<p>and</p>
<ul>
<li>String#graphemes which returns an Array of graphemes (in the same way like <code>\X</code>)</li>
</ul>
<p>What do you think?</p>
<p>Resources</p>
<ul>
<li>Unicode® Standard Annex #29: Unicode Text Segmentation: <a href="http://unicode.org/reports/tr29/" class="external">http://unicode.org/reports/tr29/</a>
</li>
<li>Related issue: <a href="https://bugs.ruby-lang.org/issues/12831" class="external">https://bugs.ruby-lang.org/issues/12831</a>
</li>
</ul> Ruby master - Bug #13292 (Closed): Invalid encodings in UTF-32https://bugs.ruby-lang.org/issues/132922017-03-08T13:14:17Zrbjl (Jan Lelis)hi@ruby.consulting
<p>Ruby is very strict about valid UTF-8 encodings, which is great.</p>
<p>Strings that encode surrogates or too large codepoints are not valid.</p>
<p>However, in UTF-32, it is possible to encode such values, and Ruby treats them as valid:</p>
<p>Example 1 (too large value)</p>
<pre><code>a = [0, 0, 17, 0].pack("C*").force_encoding("UTF-32LE") #=> "\u{110000}"
a.valid_encoding? # => true
</code></pre>
<p>Example 2 (surrogate)</p>
<pre><code>b = [0, 216, 0, 0].pack("C*").force_encoding("UTF-32LE") # => "\uD800"
b.valid_encoding? #=> true
</code></pre>
<p>The behaviour should be changed to <code>String#valid_encoding?</code> reporting <code>false</code></p>
<p>For reference: <a href="http://unicode.org/versions/Unicode9.0.0/UnicodeStandard-9.0.pdf" class="external">http://unicode.org/versions/Unicode9.0.0/UnicodeStandard-9.0.pdf</a> (page 71)</p> Ruby master - Bug #13264 (Closed): Binding#irb does not work in context of frozen objecthttps://bugs.ruby-lang.org/issues/132642017-03-01T14:00:03Zrbjl (Jan Lelis)hi@ruby.consulting
<p>This works as expected (starts IRB):</p>
<pre><code>$ ruby -r irb -e '"".instance_eval{ binding.irb }'
</code></pre>
<p>This throws an error:</p>
<pre><code>$ ruby -r irb -e '"".freeze.instance_eval{ binding.irb }'
</code></pre>
<pre><code>/home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/extend-command.rb:199:in `extend_object': can't define singleton (TypeError)
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb.rb:413:in `extend'
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb.rb:413:in `initialize'
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb.rb:713:in `new'
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb.rb:713:in `irb'
from -e:1:in `block in <main>'
from -e:1:in `instance_eval'
from -e:1:in `<main>'
</code></pre>
<p>Also fails, but slightly different error:</p>
<pre><code>ruby -r irb -e 'Object.new.freeze.instance_eval{ binding.irb }'
</code></pre>
<pre><code>/home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/extend-command.rb:200:in `extend_object': can't modify frozen object (RuntimeError)
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/extend-command.rb:200:in `extend_object'
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb.rb:413:in `extend'
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb.rb:413:in `initialize'
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb.rb:713:in `new'
from /home/jan/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb.rb:713:in `irb'
from -e:1:in `block in <main>'
from -e:1:in `instance_eval'
from -e:1:in `<main>'
</code></pre> Ruby master - Bug #12389 (Closed): Module#constants includes non-constantshttps://bugs.ruby-lang.org/issues/123892016-05-17T15:51:01Zrbjl (Jan Lelis)hi@ruby.consulting
<p>Hi Ruby Core,</p>
<p>I noticed that <code>Module#constants(false)</code> sometimes includes modules/classes with a lowercase name:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">Complex</span><span class="p">.</span><span class="nf">constants</span> <span class="c1"># => [:I]</span>
<span class="no">Complex</span><span class="p">.</span><span class="nf">constants</span><span class="p">(</span><span class="kp">false</span><span class="p">)</span> <span class="c1"># => [:compatible, :I]</span>
<span class="no">Complex</span><span class="p">.</span><span class="nf">const_defined?</span> <span class="ss">:compatible</span> <span class="c1"># NameError: wrong constant name compatible</span>
<span class="no">NameError</span><span class="p">.</span><span class="nf">constants</span> <span class="c1"># => []</span>
<span class="no">NameError</span><span class="p">.</span><span class="nf">constants</span><span class="p">(</span><span class="kp">false</span><span class="p">)</span> <span class="c1"># => [:message]</span>
</code></pre>
<p>Also:</p>
<ul>
<li>Rational --> compatible</li>
<li>IO --> generic_readable</li>
<li>IO --> generic_writable</li>
</ul> Ruby master - Bug #12382 (Closed): Deprecated constants will not print out warning when accessed ...https://bugs.ruby-lang.org/issues/123822016-05-14T12:00:37Zrbjl (Jan Lelis)hi@ruby.consulting
<p>Hi,</p>
<p>the current behavior of <code>deprecate_constant</code> is a little confusing:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">module</span> <span class="nn">Namespace</span>
<span class="k">module</span> <span class="nn">Deprecated</span>
<span class="k">end</span>
<span class="n">deprecate_constant</span> <span class="ss">:Deprecated</span>
<span class="k">end</span>
<span class="nb">puts</span> <span class="s2">"Referenced access:"</span>
<span class="no">Namespace</span><span class="o">::</span><span class="no">Deprecated</span> <span class="c1"># warning: constant Namespace::Deprecated is deprecated</span>
<span class="nb">puts</span>
<span class="nb">puts</span> <span class="s2">"Direct access (from Object):"</span>
<span class="kp">include</span> <span class="no">Namespace</span>
<span class="no">Deprecated</span> <span class="c1"># warning: constant ::Deprecated is deprecated</span>
<span class="nb">puts</span>
<span class="nb">puts</span> <span class="s2">"Direct access (from inside namespace):"</span>
<span class="k">module</span> <span class="nn">Namespace</span>
<span class="no">Deprecated</span> <span class="c1"># no warning</span>
<span class="k">end</span>
</code></pre>
<p>I would also expect a warning in the third case.</p> Ruby master - Bug #11064 (Closed): #singleton_methods for objects with special singleton_class re...https://bugs.ruby-lang.org/issues/110642015-04-12T20:35:11Zrbjl (Jan Lelis)hi@ruby.consulting
<pre><code>def nil.bla
42
end
# works
nil.bla #=> 42
nil.singleton_method(:bla) #=> #<Method: NilClass#bla>
NilClass.instance_methods.include? :bla #=> true
# does not work
nil.singleton_methods #=> []
</code></pre> Ruby master - Bug #11063 (Rejected): Special singleton class should return true for singleton_cla...https://bugs.ruby-lang.org/issues/110632015-04-12T19:50:48Zrbjl (Jan Lelis)hi@ruby.consulting
<p>This seems wrong (or at least inconsistent):</p>
<pre><code>nil.singleton_class.singleton_class? #=> false
true.singleton_class.singleton_class? #=> false
false.singleton_class.singleton_class? #=> false
</code></pre> Ruby master - Bug #9452 (Closed): Refining methods that should be privatehttps://bugs.ruby-lang.org/issues/94522014-01-26T15:01:30Zrbjl (Jan Lelis)hi@ruby.consulting
<p>Are refinements also meant to add private methods? This is what I tried:</p>
<pre><code>module R
refine Object do
def m
puts "Success!"
end
private(:m)
end
end
using R
m # success
42.m # success (= not private)
</code></pre>
<p>However, I can get near the desired functionality by defining a private method first:</p>
<pre><code>class Object
private
def m
end
end
module R
refine Object do
def m
puts "Success!"
end
end
end
using R
m # success
42.m # no success (= it is private)
</code></pre>
<p>It calls the right code. But requires global core ext.</p> Ruby master - Feature #9451 (Closed): Refinements and unary & (to_proc)https://bugs.ruby-lang.org/issues/94512014-01-26T13:57:48Zrbjl (Jan Lelis)hi@ruby.consulting
<p>Not sure if this is a bug or feature request:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s1">'minitest/autorun'</span>
<span class="nb">require</span> <span class="s1">'set'</span>
<span class="k">module</span> <span class="nn">ClassToProc</span>
<span class="n">refine</span> <span class="no">Class</span> <span class="k">do</span>
<span class="k">def</span> <span class="nf">to_proc</span>
<span class="nb">lambda</span><span class="p">{</span> <span class="o">|*</span><span class="n">args</span><span class="o">|</span> <span class="nb">self</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span> <span class="p">}</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="n">using</span> <span class="no">ClassToProc</span>
<span class="n">describe</span> <span class="s1">'Class#to_proc'</span> <span class="k">do</span>
<span class="n">it</span> <span class="s1">'works when called directly'</span> <span class="k">do</span>
<span class="no">Set</span><span class="p">.</span><span class="nf">to_proc</span><span class="p">[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">]].</span><span class="nf">must_equal</span> <span class="no">Set</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">]</span>
<span class="k">end</span>
<span class="n">it</span> <span class="s1">'fails when called via ampersand'</span> <span class="k">do</span>
<span class="p">[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">]].</span><span class="nf">map</span><span class="p">(</span><span class="o">&</span><span class="no">Set</span><span class="p">).</span><span class="nf">must_equal</span> <span class="p">[</span><span class="no">Set</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">]]</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<p>The second example errors with <em>NoMethodError: super: no superclass method `to_proc' for Set:Class</em></p>
<p>Would be great to have it, though.</p> Ruby master - Feature #4633 (Rejected): iterate method / extended version of forhttps://bugs.ruby-lang.org/issues/46332011-04-29T22:01:10Zrbjl (Jan Lelis)hi@ruby.consulting
<p>=begin<br>
The Ruby world is known for using each, but it does not always look nice (although in most cases it does).</p>
<p>I am proposing an iterate method that is nicely readable and allows easy iteration over multiple objects. It behaves like each for an single argument, but passes nils for Enumerables with multiple sizes:<br>
iterate [1,2], [3,4,5] do |e,f|<br>
puts "#{e},#{f}"<br>
end</p>
<a name="outputs"></a>
<h1 >outputs<a href="#outputs" class="wiki-anchor">¶</a></h1>
<a name="13"></a>
<h1 >1,3<a href="#13" class="wiki-anchor">¶</a></h1>
<a name="24"></a>
<h1 >2,4<a href="#24" class="wiki-anchor">¶</a></h1>
<a name="5"></a>
<h1 >,5<a href="#5" class="wiki-anchor">¶</a></h1>
<p>A simple Ruby implementation:<br>
def iterate(*params)<br>
# params.shift.zip(*params).each{ |*elements| yield *elements }<br>
raise ArgumentError, "wrong number of arguments (0)" if params.empty?</p>
<pre><code>first = params.shift
if params.empty? # single param - like each
if block_given?
first.map{|e| yield e }
else
first.map.to_enum
end
else # multiple params
max_size = [first, *params].max_by(&:count).size
padded_first = first.to_a + [nil]*(max_size - first.count) # append nils
obj = padded_first.zip *params
if block_given?
obj.map{|es| yield *es }
else
obj.map.to_enum
end
end
</code></pre>
<p>end</p>
<p>A modified version of this request (no new method/statement) could be an alternative usage of for, something like:<br>
for e,f in [1,2], [3,4,5]<br>
puts "#{e},#{f}"<br>
end</p>
<a name="outputs-2"></a>
<h1 >outputs<a href="#outputs-2" class="wiki-anchor">¶</a></h1>
<a name="13-2"></a>
<h1 >1,3<a href="#13-2" class="wiki-anchor">¶</a></h1>
<a name="24-2"></a>
<h1 >2,4<a href="#24-2" class="wiki-anchor">¶</a></h1>
<a name="5-2"></a>
<h1 >,5<a href="#5-2" class="wiki-anchor">¶</a></h1>
<p>This feature request does not add something needed, but I think, Ruby would look even more beautiful.<br>
=end</p> Ruby master - Feature #4632 (Rejected): Regexp instance method | for creating Regexp.unions https://bugs.ruby-lang.org/issues/46322011-04-29T21:59:33Zrbjl (Jan Lelis)hi@ruby.consulting
<p>=begin<br>
Regexp.union is a great feature, but it is rarely used. I can imagine, the following syntax would be quite popular:</p>
<p>For example:<br>
/Ruby\d/ | /test/i | "cheat" #=> Regexp.union( Regexp.union( /Ruby\d/, /test/i ), "cheat" )</p>
<p>It would also be cool as String method, so one can do:<br>
"jruby" | "rbx" #=> /jruby|rbx/</p>
<p>Example implementation:<br>
class Regexp<br>
def |(arg)<br>
Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s<br>
end<br>
end</p>
<p>class String<br>
def |(arg)<br>
Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s<br>
end<br>
end<br>
=end</p> Ruby master - Bug #4274 (Closed): SEGFAULT: ARGF.gets will crash if first file is not readable!https://bugs.ruby-lang.org/issues/42742011-01-13T05:45:32Zrbjl (Jan Lelis)hi@ruby.consulting
<p>=begin<br>
Hi, welcome to crash golf ;).</p>
<p>ruby -e 'gets rescue gets' CRASH!</p>
<p>or some alternative forms of it:</p>
<p>ARGV.unshift 'filename_that_does_not_exist'<br>
ARGF.gets rescue nil<br>
ARGF.gets</p>
<p>or</p>
<p>$*.unshift'X'<br>
$<.fileno rescue $<.fileno</p>
<p>However, if the first arg is readable, everything will be fine.</p>
<p>I've produced that error on various 1.9 versions.</p>
<p>1.8.7 (tested on p330) does not segfault, but displays a weird error message:</p>
<p>ruby -e 'gets rescue gets' CRASH!<br>
-e:1:in <code>gets': private method </code>gets' called for false:FalseClass (NoMethodError)</p>
<p>Appended the segfault info and a patch.</p>
<p>J-_-L<br>
=end</p> Ruby master - Bug #3690 (Rejected): method_missing in a BasicObject's singleton class - infinite ...https://bugs.ruby-lang.org/issues/36902010-08-13T22:07:40Zrbjl (Jan Lelis)hi@ruby.consulting
<p>=begin</p>
<a name="segfaults-with-all-versions-that-I-tested-193-192-191"></a>
<h1 >segfaults with all versions that I tested (1.9.3, 1.9.2, 1.9.1)<a href="#segfaults-with-all-versions-that-I-tested-193-192-191" class="wiki-anchor">¶</a></h1>
<p>obj = BasicObject.new</p>
<p>def obj.method_missing(m, *args, &block)<br>
send( m, *args, &block )<br>
end</p>
<p>puts obj.seg<br>
=end</p> Ruby master - Bug #3525 (Rejected): Enumerable#flat_map does not return a flatted enumerablehttps://bugs.ruby-lang.org/issues/35252010-07-03T03:47:49Zrbjl (Jan Lelis)hi@ruby.consulting
<p>=begin<br>
Hi,</p>
<p>the new flat_map method does not return flatted enumerables:</p>
<p>irb(main):072:0> [[1,2],2,3].flat_map{|e|e}<br>
=> [1, 2, 2, 3]<br>
irb(main):071:0> [[1,2],2,3].flat_map.to_a<br>
=> [[1, 2], 2, 3]<br>
=end</p>