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

Fix frozen error caused by frozen string literal #431

merged 4 commits into from Feb 9, 2020

Conversation

taichi-ishitani
Copy link
Contributor

Hi,

I got FrozenError when I use rubyzip gem --enable-frozen-string-literal option.

     FrozenError:
       can't modify frozen String: ""
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/crypto/decrypted_io.rb:18:in `replace'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/crypto/decrypted_io.rb:18:in `read'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/inflater.rb:32:in `produce_input'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/inflater.rb:15:in `read'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/input_stream.rb:84:in `sysread'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/entry.rb:619:in `block (2 levels) in create_file'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/entry.rb:534:in `get_input_stream'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/entry.rb:615:in `block in create_file'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/entry.rb:614:in `open'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/entry.rb:614:in `create_file'
     # ./vendor/bundle/ruby/2.7.0/gems/rubyzip-2.2.0/lib/zip/entry.rb:182:in `extract'

This PR is to fix the above error.

@taichi-ishitani taichi-ishitani changed the title Fixed frozen error caused by frozen string literal Fixe frozen error caused by frozen string literal Feb 5, 2020
@coveralls
Copy link

coveralls commented Feb 5, 2020

Coverage Status

Coverage remained the same at 95.674% when pulling 976dbd3 on taichi-ishitani:fix_frozen_error into ecd641e on rubyzip:master.

taichi-ishitani added a commit to rggen/rggen-spreadsheet-loader that referenced this pull request Feb 5, 2020
taichi-ishitani added a commit to rggen/rggen-systemverilog that referenced this pull request Feb 5, 2020
taichi-ishitani added a commit to rggen/rggen that referenced this pull request Feb 5, 2020
@taichi-ishitani taichi-ishitani changed the title Fixe frozen error caused by frozen string literal Fix frozen error caused by frozen string literal Feb 5, 2020
Copy link
Member

@jdleesmiller jdleesmiller left a comment

Choose a reason for hiding this comment

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

Good spot, thanks!

All but one of these changes look good to me (see comment).

lib/zip/file.rb Outdated
@@ -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!

@jdleesmiller
Copy link
Member

(And I have not forgotten about our discussion in #390 (comment) --- we should really get that linter set up!)

@hainesr
Copy link
Member

hainesr commented Feb 8, 2020

@jdleesmiller I have a branch in my local repo where I've done a ton of work getting rubocop up to date. I'll try and get that sorted and get a PR out this weekend.

Copy link
Member

@jdleesmiller jdleesmiller left a comment

Choose a reason for hiding this comment

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

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants