Item11719: FormPlugin: substituted field tokens in 'web' and 'topic' variables overwritten

Priority: Normal
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: FormPlugin
Branches: trunk
Reported By: FlorianSchlichting
Waiting For:
Last Change By: FlorianSchlichting
We're using FormPlugin to ease the creation of topics containing a date, via the use of a JQuery date selector. Unfortunately, SVN revision 12269 moved the field token substitution in F::Plugins::FormPlugin::_redirectToActionUrl() up so that the already substituted values of $query->param('topic') and $query->param('web') get reverted back to their former, unsubstituted value.

In practice, this looks like an empty $topic ("topic WebHome already exists"), because a topic containing tokens does not pass Foswiki::isValidTopicName().

See below for my proposed patch. I don't see why it should break anything, but I don't understand why it was moved up in SVN 12269 in the first place - something with REST?

--- a/lib/Foswiki/Plugins/
+++ b/lib/Foswiki/Plugins/
@@ -446,33 +446,33 @@ sub _redirectToActionUrl {
     my $query = Foswiki::Func::getCgiQuery()
       ; # instead of  Foswiki::Func::getRequestObject() to be compatible with older versions
     # use web and topic values
     my $topic = $formData->{options}->{topic};
     my $web   = $formData->{options}->{web};
-    _substituteFieldTokens( $query, $formData );
     if ( defined $formData->{options}->{action}
         && $formData->{options}->{action} eq 'rest' )
         $query->param( -name => 'topic', -value => "$web\.$topic" )
           if defined $topic;
         $query->param( -name => 'web', -value => $web ) if defined $web;
         $query->path_info( '/' . $formData->{options}->{restAction} )
           if defined $formData->{options}->{restAction};
     else {
         $query->param( -name => 'topic', -value => $topic ) if defined $topic;
         $query->param( -name => 'web',   -value => $web )   if defined $web;
         $query->path_info("/$web/$topic") if defined $topic && defined $web;
+    _substituteFieldTokens( $query, $formData );
     my $url =
     $url = Foswiki::Func::expandCommonVariables($url);

-- FlorianSchlichting - 02 Apr 2012

Yes, a code comment would have helped myself remember this change. It either had to do with rest or with a redirect with substituted topic and web params. If both still work with this change it should be alright.

-- ArthurClemens - 02 Apr 2012

Ah, it's not that easy. _substituteFieldTokens will just overwrite anything in $query with values in $formData, including what was just set for REST, so that breaks.

But first substituting and then overwriting with unsubstituted values for $topic, $web and restAction doesn't make sense either, so I'm overwriting with the substituted values instead and only default to the unsubstituted values in case the former are undef.

Thanks for getting back so quickly.

-- FlorianSchlichting - 03 Apr 2012

ItemTemplate edit

Summary FormPlugin: substituted field tokens in 'web' and 'topic' variables overwritten
ReportedBy FlorianSchlichting
Codebase trunk
SVN Range
AppliesTo Extension
Component FormPlugin
Priority Normal
CurrentState Closed
Checkins FormPlugin:a7d5d64d9dba
TargetRelease n/a
ReleasedIn n/a
CheckinsOnBranches trunk
trunkCheckins FormPlugin:a7d5d64d9dba
Topic revision: r5 - 03 Apr 2012, FlorianSchlichting
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy