You are here: Foswiki>Tasks Web>Item14150 (18 Feb 2017, GeorgeClark)Edit Attach

Item14150: Reload of a page in the cache fails to recompute strikeone keys.

pencil
Priority: Urgent
Current State: Closed
Released In: 2.1.3
Target Release: patch
Applies To: Engine
Component: PageCache
Branches: Release02x01 master Item13897 Item14152
Reported By: GeorgeClark
Waiting For:
Last Change By: GeorgeClark
See DirtyAreaTest

It appears that once a page with forms is cached, the only way to recompute the validation keys is to use the refresh=cache link. Even placing the form into a <dirtyarea> leaves stale validation keys in the generated HTML.

-- GeorgeClark - 29 Aug 2016

Here's a patch to try

diff --git a/core/lib/Foswiki/PageCache.pm b/core/lib/Foswiki/PageCache.pm
index c95a364..8ad3250 100644
--- a/core/lib/Foswiki/PageCache.pm
+++ b/core/lib/Foswiki/PageCache.pm
@@ -683,6 +683,14 @@ sub _handleDirtyArea {
         $prefs->popTopicContext();
     };
 
+    my $session = $Foswiki::Plugins::SESSION;
+    my $request = $session->{request};
+    my $context = $request->url( -full => 1, -path => 1, -query => 1 ) . time();
+    my $cgis = $session->{users}->getCGISession();
+    my $usingStrikeOne = $Foswiki::cfg{Validation}{Method} eq 'strikeone';
+
+    $text =~ s/<input type='hidden' name='validation_key' value='(\?.*?)' \/>/Foswiki::Validation::updateValidationKey($cgis, $context, $usingStrikeOne, $1)/gei;
+
     #Foswiki::Func::writeDebug("out text='$text'") if TRACE;
     return $text;
 }
diff --git a/core/lib/Foswiki/Validation.pm b/core/lib/Foswiki/Validation.pm
index 5441c32..3a83006 100644
--- a/core/lib/Foswiki/Validation.pm
+++ b/core/lib/Foswiki/Validation.pm
@@ -92,6 +92,15 @@ sub addValidationKey {
     return "<input type='hidden' name='validation_key' value='?$nonce' />";
 }
 
+sub updateValidationKey {
+    my ( $cgis, $context, $strikeone, $oldKey ) = @_;
+
+    # expire old key
+    expireValidationKeys($cgis, $oldKey);
+
+    return addValidationKey($cgis, $context, $strikeone);
+}
+
 =begin TML

 
Topic revision: r9 - 18 Feb 2017, GeorgeClark - This page was cached on 16 Jun 2017 - 01:50.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License