-
Notifications
You must be signed in to change notification settings - Fork 501
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 (FrozenError) in open_office.rb #509
Comments
I'm not using the rspreadsheet gem, but I'm seeing exactly the same error with Ruby 2.7.2 and roo 2.8.3, 2.8.2, 2.8.1, and 2.8.0 when reading a .csv file. |
This is caused by the "frozen_string_literal: true" directive at the top of lib/roo/open_office.rb. The logic in this file is not compatible with "frozen_string_literal: true" directive so it should be removed. e.g. str_v = '' # <--- line 480
str_v.gsub!(/'/, "'") # special case not supported by unescapeHTML, <--- line 518 This is not possible when treating all string literals as frozen. |
Is this gem still maintained? Please consider my PR to resolve this issue. |
@rknmag I know this issue is old, but can you provide a .ods file in order to reproduce the issue? I can't use the rspreadsheet gem since it's not working properly on mac anymore. |
@vanboom I 100% agree it's the frozen string literal and the fix is trivial, but it would be good to get the test coverage up so that this problem doesn't happen again. |
test_apos.ods |
Thanks for the file @rknmag I was trying with ruby 2.7.0 & 3.1.2 and did no longer run into that issue |
Recent past I have not updated my Ruby, but I have Ruby 3.0 with roo 2.9.0. I ran the same program again and got the following trace back. I am not sure whether I have to update any other gem(s) .rvm/gems/ruby-3.0.0@sprsheet/gems/roo-2.9.0/lib/roo/open_office.rb:520:in |
@rknmag Would you feel comfortable creating a unit test for it and open up a Pull Request with the fix (basically removing the frozen string literal comment from that file). I would be happy to review it and merge it back |
@rknmag I was able to reproduce the issue and submitted a fix. I have decided to keep the frozen string literal due to it's performance optimisation potential but simply fixed the |
Steps to reproduce
require 'roo'
require 'rspreadsheet'
fname = 'test_apos.ods'
wb = Rspreadsheet.new
sheet = wb.create_worksheet('Sheet1')
sheet[1,1] = '' ### Note : The cell contain empty string
wb.save(fname)
wb = Roo::Spreadsheet.open(fname)
pp wb.last_row
wb.close()
Issue
I write ods file using rspreadsheet gem. When I read back the file using roo, If any cell value contain empty string , then I get following error
..gems/roo-2.8.2/lib/roo/open_office.rb|520| in `gsub!': can't modify frozen String (FrozenError)
System configuration
Roo version: 2.8.2
Ruby version:2.6.1
The text was updated successfully, but these errors were encountered: