Item8281: Parameters does not work with special characters.

pencil
Priority: Normal
Current State: Closed
Released In:
Target Release:
Applies To: Extension
Component: TopicCreatePlugin
Branches:
Reported By: Foswiki:Main.MichaelGustavSimon
Waiting For: Main.AndrewJones
Last Change By: AndrewJones
Special characters
= and &
scrambles list of parameters.

Example:

An input field value contains
= or &
evaluated by a template to create new topic with TopicCreatePlugin.

Input field values:
  • VarA = ValueA
  • VarB = Value=B
  • VarC = ValueA&B


   * VarA = %URLPARAM{"VarA"}%
   * VarB = %URLPARAM{"VarB"}%
   * VarC = %URLPARAM{"VarC"}%

%TOPICCREATE{... parameters="VarA=ValueA&VarB=Value=B&VarC=ValueA&B"}
                                                   |             |
                                                   |        second break
                                              first break

Encoding does not work, because type url cannot be decode in created topic and other encodetypes uses
&
to encode special (
=
) characters.

-- MichaelGustavSimon - 16 Sep 2009

The problem is that the plugin uses = and & to separate the parameters. There is no way for it to know if it is meant to be part of the parameter or a separator.

Unfortunately I don't know of a way to fix this. Am open to suggestions smile

Note: the plugin uses Foswiki::Func::extractNameValuePair to get the parameters, so it is that function that cannot handle this. Therefore this same problem probably exists in many other plugins.

-- AndrewJones - 16 Sep 2009

Use another delimiter or method to evaluate parameters.

idea delimiter

< = delimiter for namevalue
> = delimiter for value assignment
%TOPICCREATE{... parameters="VarA>ValueA<VarB>Value=B<VarC>ValueA&B"}
I think gt and ls will be encoded out of the box? smile

idea method

%TOPICCREATE{... VarA="%URLPARAM{"VarA"}%" VarB="%URLPARAM{"VarB"}%" VarC="%URLPARAM{"VarC"}%"}%

-- MichaelGustavSimon - 16 Sep 2009

Your method idea looks like the best way, though we would need to keep backwards compatibility.

Will set to Confirmed. Not sure when/if I will have the time to do this, but its more than welcome to be picked up by anyone else.

-- AndrewJones - 16 Sep 2009

Maybe with following changes in TopicCreatePlugin?

line 70 ...
    my $legacy = 0;
    if ($theArgs =~ m/parameters/) {
       $legacy = 1;
    }
    my %parameters;
    my $refParameters = \%parameters;
    Foswiki::Plugins::TopicCreatePlugin::EnhancedFunctions::extractParameters($theArgs, $refParameters);

line 159 ...
if ($legacy==1) {
           next unless ( $parameters =~ m/$par=(.*?)($|&)/ );
           $passedPar = $1 || "";
           $text =~ s/%URLPARAM\{\"?$par\"?\}%/$passedPar/g;
        } else {
           $text =~ s/%URLPARAM\{\"?$par\"?\}%/$$refParameters{$par}/g;
        }

additional function
sub extractParameters {
   my ($topicCreateArgs, $refParameters) = @_;
   my @nameValuePairs = split(/\" /,$topicCreateArgs);
   foreach my $pair (@nameValuePairs) {
      my @nameValueTemp = split(/=/,$pair);
      $nameValueTemp[1] =~ s/\"//g;
      ${$refParameters}{$nameValueTemp[0]} = $nameValueTemp[1];
   }
   return $refParameters;
}

-- MichaelGustavSimon - 09 Jul 2010

I fixed it in a slightly different way. Please download the new version and let me know if you have any problems.

-- AndrewJones - 13 Jul 2010
 

ItemTemplate edit

Summary Parameters does not work with special characters.
ReportedBy Foswiki:Main.MichaelGustavSimon
Codebase 1.0.6
SVN Range Foswiki-1.0.6, Sun, 21 Jun 2009, build 4272
AppliesTo Extension
Component TopicCreatePlugin
Priority Normal
CurrentState Closed
WaitingFor AndrewJones
Checkins TopicCreatePlugin:e61a5f95a969
ReleasedIn
Topic revision: r6 - 13 Jul 2010, AndrewJones
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