Skip to content

Commit

Permalink
Item1117: Make PreferencesPlugin ignore settings inside verbatim bloc…
Browse files Browse the repository at this point in the history
…ks, which means that settings inside verbatim blocks do not break the PreferencesPlugin anymore

git-svn-id: http://svn.foswiki.org/trunk@7958 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelTempest authored and MichaelTempest committed Jun 28, 2010
1 parent 701aecf commit b615760
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
16 changes: 12 additions & 4 deletions PreferencesPlugin/lib/Foswiki/Plugins/PreferencesPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,24 @@ sub beforeCommonTagsHandler {
Foswiki::Func::setTopicEditLock( $web, $topic, 1 );

# Replace setting values by form fields but not inside comments Item4816
# and also not inside verbatim blocks Item1117
my $outtext = '';
my $insidecomment = 0;
foreach my $token ( split /(<!--|-->)/, $_[0] ) {
if ( $token =~ /<!--/ ) {
my $insideverbatim = 0;
foreach my $token ( split /(<!--|-->|<\/?verbatim\b[^>]*>)/, $_[0] ) {
if ( !$insideverbatim and $token =~ /<!--/ ) {
$insidecomment++;
}
elsif ( $token =~ /-->/ ) {
elsif ( !$insideverbatim and $token =~ /-->/ ) {
$insidecomment-- if ( $insidecomment > 0 );
}
elsif ( !$insidecomment ) {
elsif ( $token =~ /<verbatim/ ) {
$insideverbatim++;
}
elsif ( $token =~ /<\/verbatim/ ) {
$insideverbatim-- if ( $insideverbatim > 0 );
}
elsif ( !$insidecomment and !$insideverbatim) {
$token =~
s/^($Foswiki::regex{setRegex})($Foswiki::regex{tagNameRegex})\s*\=(.*$(?:\n[ \t]+[^\s*].*$)*)/
$1._generateEditField($web, $topic, $3, $4, $formDef)/gem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,57 @@ HTML
$session->finish();
}

# Item1117
sub test_edit_multiple_with_verbatim {
my $this = shift;
my $query = new Unit::Request( { prefsaction => ['edit'], } );
my $text = <<HERE;
Normal text outside form
<verbatim>
<!-- Comment-start inside verbatim is ignored
</verbatim>
%EDITPREFERENCES%
* Set FLEEGLE = floon
<verbatim>
Not in the form
* Set VERBATIMSETTING = ignored
</verbatim>
* Set FLEEGLE2 = floontoo
HERE
my $session = new Foswiki( undef, $query );
$Foswiki::Plugins::SESSION = $session;
my $result =
Foswiki::Func::expandCommonVariables( $text, $this->{test_topic},
$this->{test_web}, undef );
my $viewUrl =
Foswiki::Func::getScriptUrl( $this->{test_web}, $this->{test_topic},
'viewauth' );
Foswiki::Plugins::PreferencesPlugin::postRenderingHandler($result);

# That <!-- in the verbatim block is encoded when rendering
# and it must be encoded here or else the "html_equals" fails
$result =~ s/<!-- Comment/&lt;!-- Comment/;
$result =~ s/<(\/?)verbatim>/<$1pre>/g;
$this->assert_html_equals( <<HTML, $result );
Normal text outside form
<pre>
&lt;!-- Comment-start inside verbatim is ignored
</pre>
<form method="post" action="$viewUrl" enctype="multipart/form-data" name="editpreferences">
<input type="submit" name="prefsaction" value="Save new settings" accesskey="s" class="foswikiSubmit" />
&nbsp;
<input type="submit" name="prefsaction" value="Cancel" accesskey="c" class="foswikiButtonCancel" />
* Set <span style="font-weight:bold;" class="foswikiAlert">FLEEGLE = <input type="text" name="FLEEGLE" value="floon" size="80" class="foswikiAlert foswikiInputField" /></span>
<pre>
Not in the form
* Set VERBATIMSETTING = ignored
</pre>
* Set <span style="font-weight:bold;" class="foswikiAlert">FLEEGLE2 = <input type="text" name="FLEEGLE2" value="floontoo" size="80" class="foswikiAlert foswikiInputField" /></span></form>
HTML

$session->finish();
}

sub test_save {
my $this = shift;
my $query = new Unit::Request(
Expand Down

0 comments on commit b615760

Please sign in to comment.