Skip to content

[4.x] Parse Accept-Language and Accept-Encoding without parameters - #162

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-webclient-accept-headers
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-webclient-accept-headers

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Without an Accept-Language header, WebClient::detectLanguage() calls explode(',', null), which triggers Deprecated: explode(): Passing null to parameter #2 on PHP 8.1+ (and becomes a TypeError should PHP turn these into errors). detectEncoding() casts to string, but both keep header parameters: Accept-Encoding: gzip;q=1.0 yields gzip;q=1.0, so AbstractWebApplication::compress() never matches such clients, and values the client refuses with q=0 are listed as accepted.

Both routines now use a private parseAcceptHeader() helper that

  • accepts a missing header,
  • strips parameters (de;q=0.9 → de),
  • skips empty entries and entries with a quality of 0,
  • keeps the order in which the client listed the values (no re-sorting by quality, to stay close to the current behaviour).

Behaviour change in 4.x: a missing or empty header now gives an empty list instead of [''], and q=0 entries are no longer listed.

Testing Instructions

vendor/bin/phpunit --filter WebClientTest: new data sets for q-values and q=0 in getEncodingData()/getLanguageData(), an empty Accept-Encoding, and testDetectLanguageWithoutHeader, which turns deprecations into exceptions and fails without the change in src/.

Documentation Changes Required

docs/web-application.md ("Client detection") listed the properties as language/encoding; they are languages/encodings. The section now uses the right names and describes the parsing.

🤖 Generated with Claude Code

Without an Accept-Language header WebClient::detectLanguage() passed null
to explode(), which raises a deprecation since PHP 8.1. Both detection
routines also kept parameters such as quality values, so "gzip;q=1.0"
never matched in compress(), and values refused with q=0 were treated as
accepted.

Both headers are now parsed by one helper that strips parameters, skips
empty values and values with q=0, and accepts a missing header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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