Project

General

Profile

Actions

Bug #15873

closed

FrozenError when using OpenURI.open

Added by AlexGascon (Alex Gascon) almost 5 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
[ruby-core:92819]

Description

I just updated from Ruby 2.5.1 to 2.6.3 and I encountered a strange problem on a part that was working fine previously. It's on a Rails application, and on one of the tests I'm stubbing (using webmock) an HTTP request that we perform to an external URL. However, when trying to access the information by using OpenURI I get a FrozenError.

The following block represents a minimal reproducible example of the problem that I'm experiencing

stub_request(:get, "https://files.lol/certificate_doc.pdf").to_return(status: 200, body: "Random information", headers: {})

file_content = open("https://files.lol/certificate_doc.pdf")

FrozenError: can't modify frozen String
from /home/alex/.rbenv/versions/2.6.3/lib/ruby/2.6.0/open-uri.rb:357:in `clear'

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #14320: [PATCH] open-uri: clear string after bufferingClosedActions

Updated by nobu (Nobuyoshi Nakada) almost 5 years ago

Does it occur even if the body is "Random information".dup?

Updated by AlexGascon (Alex Gascon) almost 5 years ago

nobu (Nobuyoshi Nakada) wrote:

Does it occur even if the body is "Random information".dup?

Just tried and no, when using .dup it worked as expected!

Actions #3

Updated by nobu (Nobuyoshi Nakada) almost 5 years ago

  • Related to Feature #14320: [PATCH] open-uri: clear string after buffering added

Updated by nobu (Nobuyoshi Nakada) almost 5 years ago

  • Status changed from Open to Closed

Probably you are using frozen-string-literal pragma.
Since 2.6, OpenURI clears the buffer from Net::HTTPResponse#read_body to reduce memory usage.
See [Feature #14320].

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0