Skip to content

Ensure to correctly parse lang tracking parameter #22078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Apr 5, 2024

Description:

Matomo by defaults detects the language of a tracked visitor by parsing the http language header. As that one might not be available in all cases, the tracking API in addition allows to overwrite this by send the lang parameter.

The tracking api documentation says: An override value for the Accept-Language HTTP header field

This indicates that the provided value should be handled the same as the header value. In fact its the case, that the handling currently differs, as for the header value a `strtolower´ and some sort of clean up is applied here:

matomo/core/Common.php

Lines 836 to 847 in 9183cc6

// language tags are case-insensitive per HTTP/1.1 s3.10 but the region may be capitalized per ISO3166-1;
// underscores are not permitted per RFC 4646 or 4647 (which obsolete RFC 1766 and 3066),
// but we guard against a bad user agent which naively uses its locale
$browserLang = strtolower(str_replace('_', '-', $browserLang));
// filters
$browserLang = preg_replace($replacementPatterns, '', $browserLang);
$browserLang = preg_replace('/((^|,)chrome:.*)/', '', $browserLang, 1); // Firefox bug
$browserLang = preg_replace('/(,)(?:en-securid,)|(?:(^|,)en-securid(,|$))/', '$1', $browserLang, 1); // unregistered language tag
$browserLang = str_replace('sr-sp', 'sr-rs', $browserLang); // unofficial (proposed) code in the wild

This is currently not done for the lang parameter, as it is used as is. This PR applies a simple change, so that cleanup will be done in that case as well.

fixes #22077

Review

@sgiehl sgiehl added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Apr 5, 2024
@sgiehl sgiehl added this to the 5.1.0 milestone Apr 5, 2024
@sgiehl sgiehl added the Needs Review PRs that need a code review label Apr 5, 2024
@sgiehl sgiehl requested a review from a team April 5, 2024 12:06
@michalkleiner michalkleiner merged commit 4a6583c into 5.x-dev Apr 9, 2024
@michalkleiner michalkleiner deleted the m22077 branch April 9, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Development

Successfully merging this pull request may close these issues.

[Bug] Sending "lang" via HTTP API ignores country when upper case
2 participants