Skip to content

Recognize XML declarations when detecting response encoding - #335

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/xml-declaration-http
Open

Recognize XML declarations when detecting response encoding#335
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/xml-declaration-http

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Recognize the <?xml declaration prefix when detecting response encoding. The existing expression matches <xml instead, missing real declarations and interpreting an ordinary xml element as one.

Reproduction

An XML response with body_encoding = true and a binary body beginning <?xml version="1.0" encoding="ISO-8859-1"?> is tagged UTF-8 despite the declaration. After the one-character correction, the response uses ISO-8859-1 without changing its bytes. Conversely, an ordinary <xml version="1.0" encoding="ISO-8859-1"/> element no longer changes the encoding.

The XML declaration grammar uses the <?xml prefix.

Verification

  • Ruby 4.0.6 through rbenv; existing bundle exec rake test: 201 tests / 914 assertions / zero failures or errors, baseline and isolated patch.
  • 32 focused checks cover four XML media types, single/double quotes, space/tab/newline separators, unchanged bytes, missing declarations, ordinary elements and explicit/header encoding precedence.
  • Syntax and git diff --check pass; supplemental Lint scan has the same 25 baseline findings.
  • No test/spec files were added or modified, per this contribution's no-new-tests constraint; focused reproductions ran externally.

Compatibility and limitations

No API/dependency/Ruby-requirement change. Intentional behavior correction: real declarations are recognized; ordinary xml elements are not treated as declarations. This is not a full XML parser and does not change media-type matching or the rest of the declaration grammar. Other Ruby/OS combinations and optional external OpenSSL checks were not run.

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