froala / froala/wysiwyg-editor-ruby-sdk

Frozen string literal mutation causes deprecation warning in s3.rb on Ruby 3.4

Open
#60 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
1
Forks
0
Avg merge
23m
Merged PRs (30d)
1

Description

Hey there,

After upgrading to Ruby 3.4 and the 4.5 version of Froala we get the following [frozen string literal warnings](https://www.honeybadger.io/blog/ruby-3-4/#:~:text=Frozen%20string%20literals&text=In%20Ruby%203.4%2C%20strings%20will,you%20try%20to%20mutate%20them.) from [/lib/froala-editor-sdk/s3.rb](https://github.com/froala/wysiwyg-editor-ruby-sdk/blob/master/lib/froala-editor-sdk/s3.rb#L34C7-L34C99):

`/home/runner/work/reponame/reponame/vendor/bundle/ruby/3.4.0/gems/froala-editor-sdk-4.5.0/lib/froala-editor-sdk/s3.rb:34: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)`

The OpenSSL line is the line in question:

```
# Builds a HMAC-SHA256 digest using key and data
# Params:
# +key+:: Key to use for creating the digest
# +data+:: Data to be used for creating the digest
def self.sign(key, data)
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, key, data.force_encoding(Encoding::UTF_8))
end
```

I don't feel qualified to submit a PR to fix it, but here's the Claude suggested fix in case it's helpful. I haven't tested it.

> Here's why this warning appears:
>
> In Ruby 3.4 (and fully implemented in future versions), all string literals will be automatically frozen by default.
> In this line, OpenSSL::HMAC.digest() is being called with a string object that's being modified with force_encoding(Encoding::UTF_8).
> The warning appears because the OpenSSL library might be attempting to modify the string that's passed to it, but in future Ruby versions, this string will be frozen (immutable), causing potential errors.
>
> The most likely issue is that OpenSSL::HMAC.digest might be trying to modify the input string in place, but when strings are frozen, they can't be modified.
> To fix this issue, you could:
>
> Create a mutable copy of the string before passing it to the method:
> ```
> OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, key, data.force_encoding(Encoding::UTF_8).dup)
> ```
> Or more cleanly, make a copy and then modify it:
> ```
> data_copy = data.dup
> data_copy.force_encoding(Encoding::UTF_8)
> OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, key, data_copy)
> ```
> This warning is part of Ruby's transition toward making all string literals frozen by default for performance reasons, which has been a gradual process across several Ruby versions.

Contributor guide

No contributing guide indexed for this repository

Research direction

Inspect lib/froala-editor-sdk/s3.rb around self.sign and reproduce the warning under Ruby 3.4. Verify the chosen handling of data encoding removes the warning while preserving the HMAC result; the issue does not name a test file, so check the repository's existing test structure for relevant coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend, cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.