Skip to content

Use lazy fields accessor for empty header operations - #1672

Open
OskarEichler wants to merge 1 commit into
mikel:masterfrom
OskarEichler:codex/header-mail
Open

OskarEichler wants to merge 1 commit into
mikel:masterfrom
OskarEichler:codex/header-mail

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Use the existing fields accessor when copying a header or collecting its errors. A newly constructed empty header has no @fields yet, so dup/clone/errors currently call methods on nil.

Reproduction

Run in a fresh process against the gem:

require 'mail'
header = Mail::Header.new
p header.errors # => []
p header.dup.encoded # => empty string
p header.clone.encoded # => empty string

Verification

  • Existing bundle exec rake spec: 1,837 examples, zero failures, four existing pending, both before and after this isolated patch, on Ruby 4.0.6 via rbenv.
  • External focused checks: 51 checks; 14 baseline failing expectations → zero.
  • Nil/empty/populated headers; dup and clone; frozen originals; encoded contents; independent fields; empty errors. Existing populated-header copying behavior and clone frozen state retained.
  • Targeted syntax and git diff --check pass. Supplementary Lint output retains the same 275 existing findings by file/cop/message.

Limitations and contribution policy

CONTRIBUTING.md and relevant existing specs were reviewed; a changelog entry is included. The requesting project's explicit no-new-tests policy prevents adding or modifying repository specs, so this PR supplies an inline reproduction and runs the existing suite plus external checks. This differs from upstream's request for a regression spec and may need maintainer follow-up. No claim of coverage completeness, other Ruby engines/versions, production throughput, or live delivery. Verification uses an external bundle with the consumer's patched network/mini_mime dependencies; benchmark is supplied externally for Ruby 4 (existing #1655/#1666), without changing the gem dependencies or CI.

Breaking changes

No intended breaking changes. Empty-header operations now succeed; the general shallow-freeze contract is unchanged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant