Skip to content

Use converted strings in query and fragment setters - #249

Open
OskarEichler wants to merge 2 commits into
ruby:masterfrom
OskarEichler:codex/coercion-uri
Open

Use converted strings in query and fragment setters#249
OskarEichler wants to merge 2 commits into
ruby:masterfrom
OskarEichler:codex/coercion-uri

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Use and copy the result of to_str in both query= and fragment=. The current code calls to_str but then continues invoking String methods on the original non-String receiver.

Reproduction

Give an Object a to_str method returning 'a b', and assign it to the query or fragment of URI('https://example.test/a'). Before, delete! raises NoMethodError on the Object; after, the component is encoded like an ordinary String. Copying also protects a shared or frozen conversion result.

Verification

  • Ruby 4.0.6 through rbenv; existing bundle exec rake test: 93 tests / 3,039 assertions / zero failures or errors, both baseline and this isolated patch.
  • 42 checks cover both setters, mutable/frozen conversion results, whitespace removal, percent encoding, Unicode, empty strings, unchanged source values and clearing with nil.
  • Syntax and git diff --check pass. Supplemental Lint adds no findings against the 31-finding baseline.
  • No test/spec files added or modified, per this contribution's explicit no-new-tests constraint. Focused reproductions ran externally.

Compatibility and limitations

String-convertible values now work. Direct String and nil behavior is preserved; there is no new coercion through to_s. No public API removal, dependency change or Ruby minimum change.

Based on master 696df43b0be4c05d3a0dcf7db582126c915d860d. Other Ruby/OS runtimes were not executed locally. No production traffic or live mail/FTP services were used. Existing related PRs/issues were checked; this is a focused contribution, not exhaustive behavioral coverage.

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