Skip to content

Remove "frozen_string_literal: true" directive#21215

Closed
bcoles wants to merge 1 commit intorapid7:masterfrom
bcoles:agents
Closed

Remove "frozen_string_literal: true" directive#21215
bcoles wants to merge 1 commit intorapid7:masterfrom
bcoles:agents

Conversation

@bcoles
Copy link
Copy Markdown
Contributor

@bcoles bcoles commented Apr 1, 2026

frozen_string_literal: true breaks modules where the author has an associated email address in the mailmap.

See: https://github.com/rapid7/metasploit-framework/actions/runs/23700493046/job/69043237173

  1) modules it should behave like all modules with module type can be instantiated auxiliary scanner/smb/smb_eventlog_file_existence behaves like a module with valid metadata verifies modules metadata
     Failure/Error: self.name.strip! if self.name.present?

     FrozenError:
       can't modify frozen String: "bcoles"
     Shared Example Group: "a module with valid metadata" called from ./spec/support/shared/examples/all_modules_with_module_type_can_be_instantiated.rb:35
     Shared Example Group: "all modules with module type can be instantiated" called from ./spec/modules_spec.rb:6
[...]

@adfoster-r7
Copy link
Copy Markdown
Contributor

If it's only the strip! change triggering issues, what are your thoughts on:

-     self.name.strip! if self.name.present?

    # The parse succeeds only when a name is found
    self.name.present?
  end

  # Sets the name of the author and updates the email if it's a known author.
  # @param name [String] the name to set
  def name=(name)
+   name = name.strip if name
    if KNOWN.has_key?(name)
      self.email = KNOWN[name]
    end
    @name = name
  end

Long-term frozen string literals will be the path of least resistance for Ruby (slightly older article at this point):

Ruby 3.4 takes the first step in a multi-version transition to frozen string literals by default. Your Rails app will continue working exactly as before, but Ruby now provides opt-in warnings to help you prepare. [..]

Ruby is implementing frozen string literals gradually over three releases:

@bcoles bcoles closed this Apr 1, 2026
@github-project-automation github-project-automation bot moved this from Todo to Done in Metasploit Kanban Apr 1, 2026
@bcoles bcoles deleted the agents branch April 1, 2026 14:57
@bcoles
Copy link
Copy Markdown
Contributor Author

bcoles commented Apr 1, 2026

If it's only the strip! change triggering issues, what are your thoughts on:

-     self.name.strip! if self.name.present?

    # The parse succeeds only when a name is found
    self.name.present?
  end

  # Sets the name of the author and updates the email if it's a known author.
  # @param name [String] the name to set
  def name=(name)
+   name = name.strip if name
    if KNOWN.has_key?(name)
      self.email = KNOWN[name]
    end
    @name = name
  end

That seems like a reasonable approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants