You are here: Foswiki>Tasks Web>Item12299 (05 Jul 2015, GeorgeClark)Edit Attach

Item12299: don't rewrite the parameter list of named sections in template topics

pencil
Priority: Enhancement
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component:
Branches: trunk
Reported By: MichaelDaum
Waiting For:
Last Change By: GeorgeClark
When you create a new topic with a templatetopic that has got named sections of the form

%STARTSECTION{"answer"}%

<!-- put your answer here -->

%ENDSECTION{"answer"}%

then these are rewritten as

%STARTSECTION{name="answer" type="section"}%

<!-- put your answer here -->

%ENDSECTION{name="answer" type="section"}%

These two forms are basically equivalent. Yet the second one is more difficult to read and maintain. I constantly find me cleaning these up as they appear. I'd prefer the section parameters to remain as they were crafted in the template topic.

The problem is caused by Foswiki::expandMacrosOnTopicCreation. All sections in a template topic are parsed and inserted back in while stripping of templateonly sections. The parameter list to %STARTSECTION/ENDSECTION are put back using the stringify() method of Foswiki::Attrs. This however is creating a canonical and more verbose form of the parameter list. Instead, it should insert back the parameter list as it was before, stored in the _RAW property of a Foswiki::Attr.

This patch fixes it:
--- lib/Foswiki.pm      (revision 16213)
+++ lib/Foswiki.pm      (working copy)
@@ -2544,10 +2544,10 @@
                     $ntext =
                         substr( $ntext, 0, $start )
                       . '%STARTSECTION{'
-                      . $s->stringify() . '}%'
+                      . $s->{_RAW} . '}%'
                       . substr( $ntext, $start, $end - $start )
                       . '%ENDSECTION{'
-                      . $s->stringify() . '}%'
+                      . $s->{_RAW} . '}%'
                       . substr( $ntext, $end, length($ntext) );
                 }
             }
@@ -2578,10 +2578,10 @@
                     $ntext =
                         substr( $ntext, 0, $start )
                       . '%STARTSECTION{'
-                      . $s->stringify() . '}%'
+                      . $s->{_RAW} . '}%'
                       . substr( $ntext, $start, $end - $start )
                       . '%ENDSECTION{'
-                      . $s->stringify() . '}%'
+                      . $s->{_RAW} . '}%'
                       . substr( $ntext, $end, length($ntext) );
             

Crawford noted on IRC, that this might be "dangerous" for some reason...

-- MichaelDaum - 17 Dec 2012

If you look just a few lines higher in the code you will see a call to $s->remove i.e the parameter list is being modified. If you simply instantiate _RAW you will miss this modification completely. That's "some reason".

-- CrawfordCurrie - 17 Dec 2012

If you look a few more lines further down the code you will see that the attributes removed are never part of the _RAW string. Parameters removed are start and end. These are offset markers into the topic text set when parsing sections. They are never set by the user or overwritten by parseSections anyway.

-- MichaelDaum - 18 Dec 2012

OK, looks like it works for sections then. Just make sure there's a big warning in the code and don't make a habit of it wink

-- CrawfordCurrie - 18 Dec 2012

 

ItemTemplate edit

Summary don't rewrite the parameter list of named sections in template topics
ReportedBy MichaelDaum
Codebase trunk
SVN Range
AppliesTo Engine
Component
Priority Enhancement
CurrentState Closed
WaitingFor
Checkins distro:1e1a4108d4dd
TargetRelease major
ReleasedIn 2.0.0
CheckinsOnBranches trunk
trunkCheckins distro:1e1a4108d4dd
Release01x01Checkins
Topic revision: r9 - 05 Jul 2015, GeorgeClark
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