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

can't modify frozen String when run with --enable=frozen-string-literal flag #665

Open
khiav223577 opened this issue Jun 23, 2023 · 1 comment
Labels
Done in caxlsx This has already been solved in the caxlsx fork.

Comments

@khiav223577
Copy link

khiav223577 commented Jun 23, 2023

My rails project, which is running with RUBYOPT="--enable-frozen-string-literal", encounter this problem.
The Error message is:

Failure/Error: package.serialize(tempfile)

     FrozenError:
       can't modify frozen String: ""
     # /home/khiav/.rvm/gems/ruby-3.0.0/gems/axlsx-2.0.1/lib/axlsx/rels/relationships.rb:23:in `to_xml_string'
     # /home/khiav/.rvm/gems/ruby-3.0.0/gems/axlsx-2.0.1/lib/axlsx/package.rb:197:in `parts'
     # /home/khiav/.rvm/gems/ruby-3.0.0/gems/axlsx-2.0.1/lib/axlsx/package.rb:160:in `write_parts'
     # /home/khiav/.rvm/gems/ruby-3.0.0/gems/axlsx-2.0.1/lib/axlsx/package.rb:105:in `block in serialize'
     # /home/khiav/.rvm/gems/ruby-3.0.0/gems/rubyzip-1.0.0/lib/zip/output_stream.rb:49:in `open'
     # /home/khiav/.rvm/gems/ruby-3.0.0/gems/axlsx-2.0.1/lib/axlsx/package.rb:104:in `serialize'

It looks like the default arguments of to_xml_string method is a frozen string when running with the flag.

def to_xml_string(str = '')

I suggest we replace '' with String.new, so that the empty string will never be frozen.

@noniq
Copy link
Collaborator

noniq commented Jun 23, 2023

Just for the record: This has already been fixed in caxlsx, see caxlsx/caxlsx@fabe8cb Not yet released though, will probably be in v4.0.0

@noniq noniq added the Done in caxlsx This has already been solved in the caxlsx fork. label Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Done in caxlsx This has already been solved in the caxlsx fork.
Projects
None yet
Development

No branches or pull requests

2 participants