Problem/Motivation
If the session language provider is enabled and page cache is enabled (and #815526: Session language switcher prevents pages from being cached is fixed), we can have duplicate page cache entries for the same content because the language switcher block appends the language query string parameter even for the default language link. If no language parameter is found we may fall back to the default language and thus having the same content for, say, http://example.org/
and http://example.org/?language=en
.
Proposed resolution
Fix the issue by forbidding query string language parameters when page cache is enabled and the parameter value matches the default language.
Original report by @plach
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a patch | Instructions | ||
Reroll the patch if it no longer applies. | Instructions | ||
Manually test the patch | Novice | Instructions | |
Add steps to reproduce the issue | Novice | Instructions |
Comment | File | Size | Author |
---|---|---|---|
#67 | 815544-67.patch | 1.48 KB | sahil.goyal |
#66 | reroll_diff_63-66.txt | 1.87 KB | Medha Kumari |
#66 | 815544-66.patch | 2.36 KB | Medha Kumari |
#65 | interdiff_62-65.txt | 592 bytes | sahil.goyal |
#65 | 815544-65.patch | 2.21 KB | sahil.goyal |
Comments
Comment #1
plachThe attached patch should fix the issue by forbidding query string language parameters when page cache is enabled and the parameter value matches the default language.
This depends on #815526-1: Session language switcher prevents pages from being cached to be tested properly.
Comment #2
plachTrailing whitespace.
Powered by Dreditor.
Comment #4
plachHuh? Now the bot reports green. Changing the status back to CNR.
Comment #5
plachThe latest patch does not take into account possible language providers "in between" session and default ones.
Postponed to #817114: Deprecate the session language detection method.
Comment #6
sunTests may fail, because these are persistent statics, not drupal_static()s (i.e., not reset for each test case).
0 should be CACHE_DISABLED, I guess.
I'm missing a simple test that proves that we're fixing an actual bug with that patch. Also, shouldn't we simply disable page caching if we negotiated a session language?
Powered by Dreditor.
Comment #7
plachChanging to "needs work" since #817114: Deprecate the session language detection method has been postponed to this one.
Comment #8
plach@sun:
Incredibly we have no such constant in core.
Let's see if this flies, then I'll write some simpletests.
In core, browser detection requires page cache to be turned off, while user detection requires an authenticated user.
The attached patch implements a variant of the approach suggested above (through a minor API change): to ensure that anonymous users always get different URLs for different contents, only language detection methods defining an URL rewrite callback are allowed to be executed in this context. Moreover a language detection method can (still) specify a cache mode preference.
This way we are sure that no other language detection method can be enabled below the session one without affecting the URL itself (and thus, hopefully, the page content).
After ensuring this we can safely skip the
language
parameter for the default language, thus avoiding page cache duplicates.The patch additionally performs a small change to
language_initialize()
to allow each language object to track the language provider that detected it. Actually this change is not used in the patch (it's a heritage of a previous attempt), but I thought it can be useful and decided to keep it.Comment #9
plachSmall but actual API change.
Comment #10
plachAfter beta I'm afraid this needs an ok from committers, as the latest patch introduces a minor API change.
As you can read in http://api.drupal.org/api/function/hook_language_negotiation_info/7, the
'url_rewrite'
callback tells the language system whether a language detection method may affect URLs. This patch introduces a different behavior when this callback is not set: the language detection method is ignored if we have an anonymous user and page cache is enabled. We still have a way to force the previous behavior by setting the'url_rewrite'
value toFALSE
(i.e. giving it an empty value).Comment #11
plachBugs are fixed in the development version first, backported then.
The patch needs a reroll.
Comment #12
Albert Volkman CreditAttribution: Albert Volkman commentedTagging
Comment #13
Albert Volkman CreditAttribution: Albert Volkman commentedThis is my attempt at simply bring in #8 to D8.
Comment #15
Albert Volkman CreditAttribution: Albert Volkman commentedOops.
Comment #16
tim.plunkett#15: language_dup_cache-815544-15.patch queued for re-testing.
Comment #18
Albert Volkman CreditAttribution: Albert Volkman commentedRe-roll.
Comment #19
ceardach CreditAttribution: ceardach commentedRemove "Needs reroll" because latest patch passes.
Comment #20
vsawant CreditAttribution: vsawant commentedThis patch no longer applies.
Comment #21
Albert Volkman CreditAttribution: Albert Volkman commentedHere's a re-roll, but I haven't tested it locally.
Comment #23
Albert Volkman CreditAttribution: Albert Volkman commentedUpdating $user var to use currentUser property.
Comment #24
Albert Volkman CreditAttribution: Albert Volkman commentedComment #26
Albert Volkman CreditAttribution: Albert Volkman commentedD'oh.
Comment #27
plachThanks!
Btw, this comment is outdated and does not wrap correctly at column 80 :)
Comment #30
johnennew CreditAttribution: johnennew commentedComment #31
johnennew CreditAttribution: johnennew commentedComment #32
sdelbosc CreditAttribution: sdelbosc commented-- Content removed (posted on wrong issue) --
Comment #33
wranvaud CreditAttribution: wranvaud commentedI'm in drupalcon amsterdam, working on this issue
Comment #34
wranvaud CreditAttribution: wranvaud commentedAPI changed, function locale_language_url_rewrite_session is now LanguageNegotiationSession::processOutbound(). I've updated the comment pointed by @plach at comment #27
Comment #35
wranvaud CreditAttribution: wranvaud commentedCleaning up patch, replaced tab with spaces, fixed indentation
Comment #36
Mac_Weber CreditAttribution: Mac_Weber commentedshall this comparison be "==="?
Comment #37
jhedstromPatch still applies. Removing the API change tag, since the patch in #35 doesn't appear to involve one from what I can tell.
Comment #38
jhedstromComment #39
jhedstromAlso, would adding a test for this be feasible?
Comment #40
pingers CreditAttribution: pingers commentedUse $this->currentUser->isAnonymous().
"It may be removed in Lang...." is simpler language.
Comment #41
Mac_Weber CreditAttribution: Mac_Weber commented$cache
is undefinedComment #42
Mac_Weber CreditAttribution: Mac_Weber commentedComment #43
rpayanmHere the patch.
Comment #44
jhedstromPatch in #43 doesn't address #41.
Comment #45
disasm CreditAttribution: disasm at AppliedTrust commentedLets get some manual testing and automated tests written for this issue.
Comment #46
marcoscanoWorking on this on the mentored sprint in DCon Barcelona.
Will do some manual testing and steps to reproduce.
Comment #53
vacho CreditAttribution: vacho at Skilld commentedComment #54
vacho CreditAttribution: vacho at Skilld commentedPatch rerolled. However $cache and $default still undefined.
Comment #56
pradeepjha CreditAttribution: pradeepjha at Srijan | A Material+ Company for Drupal India Association commentedPatch rerolled for 8.8.x.
Comment #61
Nitin shrivastava CreditAttribution: Nitin shrivastava at OpenSense Labs commentedCreated patch for 9.4.x. Please review this patch and move it
Comment #62
Anchal_gupta CreditAttribution: Anchal_gupta at Srijan | A Material+ Company for Drupal India Association commentedI have fixed the CCF error
Comment #63
Akram KhanTrying to Fix
Comment #65
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedtrying to fix the CI issue as there is some CSpell errors right there so corresponding to that providing the patch along with the interadiff
Comment #66
Medha KumariRerolled the patch#63 in Drupal 9.4.x.
Comment #67
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedTrying to fix the CCF, As i seen in my #65 i missed to add some line of code, So thanx @Medha Kumari to resolve it.
Comment #70
catchRe-titling since the title makes this seem like a page cache bug, it's more about URL cleanliness.