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.
Remaining tasks
Convert to an MR
Add test
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| 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 |
Issue fork drupal-815544
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
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
languageparameter 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 commentedTagging
Comment #13
albert volkman commentedThis is my attempt at simply bring in #8 to D8.
Comment #15
albert volkman commentedOops.
Comment #16
tim.plunkett#15: language_dup_cache-815544-15.patch queued for re-testing.
Comment #18
albert volkman commentedRe-roll.
Comment #19
ceardach commentedRemove "Needs reroll" because latest patch passes.
Comment #20
vsawant commentedThis patch no longer applies.
Comment #21
albert volkman commentedHere's a re-roll, but I haven't tested it locally.
Comment #23
albert volkman commentedUpdating $user var to use currentUser property.
Comment #24
albert volkman commentedComment #26
albert volkman commentedD'oh.
Comment #27
plachThanks!
Btw, this comment is outdated and does not wrap correctly at column 80 :)
Comment #30
johnennew commentedComment #31
johnennew commentedComment #32
sdelbosc commented-- Content removed (posted on wrong issue) --
Comment #33
wranvaud commentedI'm in drupalcon amsterdam, working on this issue
Comment #34
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 commentedCleaning up patch, replaced tab with spaces, fixed indentation
Comment #36
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 commentedUse $this->currentUser->isAnonymous().
"It may be removed in Lang...." is simpler language.
Comment #41
mac_weber commented$cacheis undefinedComment #42
mac_weber commentedComment #43
rpayanmHere the patch.
Comment #44
jhedstromPatch in #43 doesn't address #41.
Comment #45
disasm 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 commentedComment #54
vacho commentedPatch rerolled. However $cache and $default still undefined.
Comment #56
pradeepjha commentedPatch rerolled for 8.8.x.
Comment #61
nitin shrivastava commentedCreated patch for 9.4.x. Please review this patch and move it
Comment #62
anchal_gupta commentedI have fixed the CCF error
Comment #63
akram khanTrying to Fix
Comment #65
sahil.goyal 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 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.
Comment #72
quietone commentedComment #75
nexusnovaz commentedConverted patch #66 to an MR (!9533). Unsure where to start on tests, though i will be following
Comment #77
mrinalini9 commentedFixed pipeline failure issues in the MR, please review it.
Thanks!
Comment #78
smustgrave commentedpreviously tagged for tests which still appear to be needed.
Comment #80
quietone commentedI am removing the 'Novice' tag because what task someone new to Drupal contribution is not clearly defined. And adding a test is typically not suitable. And if it manual testing, then steps are needed on how to do that.