Skip to content

Commit

Permalink
Adding support for the :utf-8 access mode in File.new (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 14, 2021
1 parent fe6a315 commit 06e47d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/memfs/io.rb
Expand Up @@ -214,7 +214,7 @@ def readable?
def str_to_mode_int(mode)
return mode unless mode.is_a?(String)

unless mode =~ /\A([rwa]\+?)([bt])?(:bom)?(\|.+)?\z/
unless mode =~ /\A([rwa]\+?)([bt])?(:(bom|UTF-8|utf-8))?(\|.+)?\z/
fail ArgumentError, "invalid access mode #{mode}"
end

Expand Down
10 changes: 10 additions & 0 deletions spec/memfs/file_spec.rb
Expand Up @@ -914,6 +914,16 @@ module MemFs
expect(subject.send(:opening_mode)).to eq File::RDONLY
end

it 'handles the :utf-8 option' do
subject = described_class.new('/test-file', 'r:utf-8')
expect(subject.send(:opening_mode)).to eq File::RDONLY
end

it 'handles the :UTF-8 option' do
subject = described_class.new('/test-file', 'r:UTF-8')
expect(subject.send(:opening_mode)).to eq File::RDONLY
end

it 'handles the |utf-8 option' do
subject = described_class.new('/test-file', 'r|utf-8')
expect(subject.send(:opening_mode)).to eq File::RDONLY
Expand Down

0 comments on commit 06e47d9

Please sign in to comment.