Skip to content

Commit

Permalink
Item9480: Fix _renderZone sometimes not flushing zones
Browse files Browse the repository at this point in the history
Actually, this is a work-around for {OptimizePageLayout} = 0.

The problem was that in this case, we render both head and body zones together.

But we also call renderTML and expandMacros at the end of this process; if a
plugin has registered event handlers that add more content to either zone, then
we can no longer trust that _renderZone is going to finish with "empty" zones.

So, I simiply added a test for {OptimizePageLayout} to render the body zone,
instead of  relying on it being empty from the _renderZone(head) call.

git-svn-id: http://svn.foswiki.org/trunk@8531 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Aug 18, 2010
1 parent ab25ac9 commit 7001260
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions core/lib/Foswiki.pm
Expand Up @@ -65,7 +65,7 @@ our $RELEASE;
our $TRUE = 1;
our $FALSE = 0;
our $engine;
our $TranslationToken = "\0"; # Do not deprecate - used in many plugins
our $TranslationToken = "\0"; # Do not deprecate - used in many plugins

# Note: the following marker is used in text to mark RENDERZONE
# macros that have been hoisted from the source text of a page. It is
Expand Down Expand Up @@ -749,7 +749,7 @@ JS

if ( $contentType ne 'text/plain' ) {

$text = $this->_renderZones( $text );
$text = $this->_renderZones($text);
}

# SMELL: can't compute; faking content-type for backwards compatibility;
Expand Down Expand Up @@ -3326,9 +3326,8 @@ sub _renderZone {
$params->{header} ||= '';
$params->{footer} ||= '';
$params->{chomp} ||= 'off';
$params->{missingformat} =
'$id: requires= missing ids: $missingids';
$params->{format} = '$item<!--<literal>$missing</literal>-->'
$params->{missingformat} = '$id: requires= missing ids: $missingids';
$params->{format} = '$item<!--<literal>$missing</literal>-->'
unless defined $params->{format};
$params->{separator} = '$n()' unless defined $params->{separator};

Expand Down Expand Up @@ -3385,10 +3384,10 @@ sub _renderZone {
my @result = ();
my $missingformat = $params->{missingformat};
foreach my $item (@total) {
my $text = $item->{text};
my @missingids = @{ $item->{missingrequires} };
my $missingformat = ( scalar(@missingids) )
? $params->{missingformat} : '';
my $text = $item->{text};
my @missingids = @{ $item->{missingrequires} };
my $missingformat =
( scalar(@missingids) ) ? $params->{missingformat} : '';

if ( $params->{'chomp'} ) {
$text =~ s/^\s+//g;
Expand All @@ -3401,10 +3400,11 @@ sub _renderZone {
next unless $text;
my $id = $item->{id} || '';
my $line = $params->{format};
if (scalar(@missingids)) {
if ( scalar(@missingids) ) {
$line =~ s/\$missing\b/$missingformat/g;
$line =~ s/\$missingids\b/join(', ', @missingids)/ge;
} else {
}
else {
$line =~ s/\$missing\b/\$id/g;
}
$line =~ s/\$item\b/$text/g;
Expand All @@ -3413,12 +3413,10 @@ sub _renderZone {
$line = expandStandardEscapes($line);
push @result, $line if $line;
}

my $result =
expandStandardEscapes(
$params->{header}
. join( $params->{separator}, @result )
. $params->{footer} );
expandStandardEscapes( $params->{header}
. join( $params->{separator}, @result )
. $params->{footer} );

# delay rendering the zone until now
$result = $topicObject->expandMacros($result);
Expand Down Expand Up @@ -3491,10 +3489,15 @@ sub _renderZones {
$text =~ s!(</head>)!$headZone\n$1!i if $headZone;

# get the body zone and insert it at the end of the </body>
# *if it has not already been rendered*
my $bodyZone = _renderZone( $this, 'body', { chomp => "on" } );
# SMELL: Item9480 - can't trust that _renderzone(head) above has truly
# flushed both body and head zones empty when {OptimizePageLayout} = 0.
my $bodyZone;
if ( $Foswiki::cfg{OptimizePageLayout} ) {
_renderZone( $this, 'body', { chomp => "on" } );
}

if ($bodyZone) {

# Unless optimize mode is enabled, or the body zone has been
# explicitly expanded by %RENDERZONE{"body"}%, the body zone
# is appended to the head.
Expand Down

0 comments on commit 7001260

Please sign in to comment.