Skip to content

Marcel 1.1.0 emits Ruby 3.4 frozen string literal deprecation warnings #139

@andynu

Description

@andynu

Marcel 1.1.0 emits Ruby 3.4 deprecation warnings despite PR #123.

Reproduction

require 'marcel'
require 'stringio'

io = StringIO.new("test content")
Marcel::MimeType.for(io)

Run with Ruby's verbose warnings (as Rails test suites do):

$ ruby -W2 repro.rb

/gems/marcel-1.1.0/lib/marcel/magic.rb:120: warning: literal string will be frozen in the future

Root Cause

PR #123 fixed line 122 but missed lines 120-121:

def self.magic_match(io, method)
  return magic_match(StringIO.new(io.to_s), method) unless io.respond_to?(:read)

  io.binmode if io.respond_to?(:binmode)                    # ← line 120: triggers warning
  io.set_encoding(Encoding::BINARY) if io.respond_to?(:set_encoding)  # ← line 121: triggers warning
  buffer = (+"").encode(Encoding::BINARY)                   # ← line 122: fixed by PR #123

  MAGIC.send(method) { |type, matches| magic_match_io(io, matches, buffer) }
end

Calling these methods on StringIO triggers Ruby 3.4's frozen string literal warnings.

Impact

Rails applications see warnings polluting test output.

Environment

  • Ruby: 3.4.5
  • Marcel: 1.1.0
  • Trigger: -W2 flag (verbose warnings, used by Rails)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions