Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix frozen error caused by frozen string literal #431

Merged
merged 4 commits into from Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/zip/crypto/decrypted_io.rb
Expand Up @@ -25,7 +25,7 @@ def eof
end

def buffer
@buffer ||= ''.dup
@buffer ||= +''
end

def input_finished?
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/entry.rb
Expand Up @@ -615,7 +615,7 @@ def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exi
get_input_stream do |is|
bytes_written = 0
warned = false
buf = ''.dup
buf = +''
while (buf = is.sysread(::Zip::Decompressor::CHUNK_SIZE, buf))
os << buf
bytes_written += buf.bytesize
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/extra_field.rb
Expand Up @@ -26,7 +26,7 @@ def extra_field_type_unknown(binstr, len, i)
end

def create_unknown_item
s = ''.dup
s = +''
class << s
alias_method :to_c_dir_bin, :to_s
alias_method :to_local_bin, :to_s
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/file.rb
Expand Up @@ -402,7 +402,7 @@ def get_entry(entry)
# Creates a directory
def mkdir(entryName, permissionInt = 0o755)
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)
entryName = entryName.dup.to_s
entryName = +entryName.to_s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entryName = +entryName.to_s
entryName = entryName.dup.to_s

I am not sure about this one --- I think the dup here is not necessarily to get an unfrozen entryName but instead to avoid mutating the entryName argument. + does not duplicate the string if it's not frozen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaredbeck ,
Thank you for your comment !
OK, I will revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

entryName << '/' unless entryName.end_with?('/')
@entry_set << ::Zip::StreamableDirectory.new(@name, entryName, nil, permissionInt)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/inflater.rb
Expand Up @@ -3,7 +3,7 @@ class Inflater < Decompressor #:nodoc:all
def initialize(*args)
super

@buffer = ''.dup
@buffer = +''
@zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
end

Expand Down