Skip to content

Commit

Permalink
Item1888: Make PreferencesPlugin able to modify more of the settings …
Browse files Browse the repository at this point in the history
…that Foswiki accepts, without corrupting things.

   * Use Foswii's regexes for the tag name instead of \w+
   * Allow for all of the variations of spacing before and after =
   * Don't corrupt multi-line preferences when saving 


git-svn-id: http://svn.foswiki.org/trunk@7942 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelTempest authored and MichaelTempest committed Jun 27, 2010
1 parent 2abd5ac commit fbe98b8
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions PreferencesPlugin/lib/Foswiki/Plugins/PreferencesPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ sub beforeCommonTagsHandler {
}
elsif ( !$insidecomment ) {
$token =~
s(^((?:\t| )+\*\s(Set|Local)\s*)(\w+)\s*\=(.*$(\n[ \t]+[^\s*].*$)*))
($1._generateEditField($web, $topic, $3, $4, $formDef))gem;
s/^($Foswiki::regex{setRegex})($Foswiki::regex{tagNameRegex})\s*\=(.*$(?:\n[ \t]+[^\s*].*$)*)/
$1._generateEditField($web, $topic, $3, $4, $formDef)/gem;
}
$outtext .= $token;
}
Expand Down Expand Up @@ -136,8 +136,10 @@ s(^((?:\t| )+\*\s(Set|Local)\s*)(\w+)\s*\=(.*$(\n[ \t]+[^\s*].*$)*))
my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );

# SMELL: unchecked implicit untaint of value?
$text =~ s(^((?:\t| )+\*\s(Set|Local)\s)(\w+)\s\=\s(.*)$)
($1._saveSet($query, $web, $topic, $3, $4, $formDef))mgeo;
# $text =~ s/($Foswiki::regex{setVarRegex})/
$text =~
s/^($Foswiki::regex{setRegex})($Foswiki::regex{tagNameRegex})\s*\=(.*$(?:\n[ \t]+[^\s*].*$)*)/
$1._saveSet($query, $web, $topic, $3, $4, $formDef)/mgeo;
Foswiki::Func::saveTopic( $web, $topic, $meta, $text );
}
Foswiki::Func::setTopicEditLock( $web, $topic, 0 );
Expand Down Expand Up @@ -191,13 +193,26 @@ sub _generateEditField {
}
unless ($html) {

# No form definition, default to text field.
$html = CGI::textfield(
-class => 'foswikiAlert foswikiInputField',
-name => $name,
-size => 80,
-value => $value
);
if ($value =~ /\n/) {
my $rows = 1;
$rows++ while $value =~ /\n/g;
# No form definition and there are newlines, default to textarea
$html = CGI::textarea(
-class => 'foswikiAlert foswikiInputField',
-name => $name,
-cols => 80,
-rows => $rows,
-default => $value);
}
else {
# No form definition and no newlines, default to text field.
$html = CGI::textfield(
-class => 'foswikiAlert foswikiInputField',
-name => $name,
-size => 80,
-value => $value
);
}
}

push( @shelter, $html );
Expand Down

0 comments on commit fbe98b8

Please sign in to comment.