Skip to content

Commit

Permalink
Initialize StringIO without options in Ruby < 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcPer committed Aug 4, 2024
1 parent f2d5b92 commit 74a9e0d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1605,8 +1605,7 @@ def open(filename_or_io, mode="r", **options)
options.delete_if {|k, _| /newline\z/.match?(k)}

if filename_or_io.is_a?(StringIO)
filter_supported_stringio_open_opts!(file_opts)
f = StringIO.new(filename_or_io.string, **file_opts)
f = init_stringio!(filename_or_io.string, mode, **file_opts)
else
begin
f = File.open(filename_or_io, mode, **file_opts)
Expand Down Expand Up @@ -1925,12 +1924,14 @@ def may_enable_bom_detection_automatically(filename_or_io,
end

if RUBY_VERSION < "2.7"
def filter_supported_stringio_open_opts!(opts)
def init_stringio!(str, mode, opts)
opts.reject! { |k, _| k == :universal_newline || DEFAULT_OPTIONS.key?(k) }
raise ArgumentError, "Unsupported options parsing StringIO: #{opts.keys}" unless opts.empty?
StringIO.new(str)
end
else
def filter_supported_stringio_open_opts!(opts)
def init_stringio!(str, mode, opts)
StringIO.new(str, mode, **opts)
end
end
end
Expand Down

0 comments on commit 74a9e0d

Please sign in to comment.