https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-08-22T14:48:15ZRuby Issue Tracking SystemRuby master - Bug #13835: Using 'open-uri' with 'tempfile' causes an exceptionhttps://bugs.ruby-lang.org/issues/13835?journal_id=662592017-08-22T14:48:15Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>Indeed, sounds like a bug; at the least it is somewhat surprising behaviour to me. Not<br>
that I think I would have ever found the above behaviour, I always used open-uri with<br>
a remote URL so far. :)</p> Ruby master - Bug #13835: Using 'open-uri' with 'tempfile' causes an exceptionhttps://bugs.ruby-lang.org/issues/13835?journal_id=662602017-08-22T21:35:28Zkigster (Konstantin Gredeskoul)
<ul></ul><p>shevegen (Robert A. Heiler) wrote:</p>
<blockquote>
<p>Indeed, sounds like a bug; at the least it is somewhat surprising behaviour to me. Not<br>
that I think I would have ever found the above behaviour, I always used open-uri with<br>
a remote URL so far. :)</p>
</blockquote>
<p>Hm, as I remember, the first argument to <code>open</code> should be a URl or a path, not a <code>Tempfile</code> instance, right?</p>
<p>In other words, changing the above example to <code>open(temp_file.path, 'a')</code> fixes the error for me.</p> Ruby master - Bug #13835: Using 'open-uri' with 'tempfile' causes an exceptionhttps://bugs.ruby-lang.org/issues/13835?journal_id=662772017-08-25T02:03:01Zkernigh (George Koehler)xkernigh@netscape.net
<ul></ul><p>Turns out that <code>open(temp_file, 'a')</code> works with the original open, but fails after loading open-uri.</p>
<p>This is because the instances of Tempfile respond to <code>to_path</code>, just like instances of File or Pathname. So <code>open(temp_file, 'a')</code> acts like <code>open(temp_file.to_path, 'a')</code>. I was confused because the documentation for <code>Kernel.open</code> (and other methods like <code>File.path</code>) has no mention of <code>to_path</code>. I needed to read Ruby's source code to learn about it.</p>
<p>The bug happens after loading open-uri. Then <code>open(temp_file, 'a')</code> tries to call <code>temp_file.open('a')</code>, but <code>Tempfile#open</code> fails to do what open-uri expects, and instead raises the ArgumentError.</p> Ruby master - Bug #13835: Using 'open-uri' with 'tempfile' causes an exceptionhttps://bugs.ruby-lang.org/issues/13835?journal_id=801072019-07-26T21:45:15Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>This issue no longer occurs in the master branch, probably due to <a class="changeset" title="Warn open-uri's "open" method at Kernel. Use URI.open instead. Thanks for the patch by jeremyev..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/05aac90a1bcfeb180f5e78ea8b00a4d1b04d5eed">05aac90a1bcfeb180f5e78ea8b00a4d1b04d5eed</a>. That commit changed the behavior so that <code>open</code> is not called on the first argument to <code>Kernel#open</code> if the object responds to <code>to_path</code>. This was done to avoid an warning when using <code>Kernel#open</code> with <code>Pathname</code> instances, but it looks like it fixed this issue as well.</p>