This question about Topic Markup Language and applications: Answered

Issue when Topic Display Title value includes single quote

Ref: Tasks/Item12830, Development/TopicDisplayName.

I have a Library app. Each page uses the LibTitle value from its attached form to set a TOPICTITLE variable.
  * Set TOPICTITLE = %FORMFIELD{"LibTitle" topic="%INCLUDINGTOPIC%"}%

For one entry, the LibTitle value (Jung's Typology) contained a single quote . The TOPICTITLE broke at the quote mark and the page could not be displayed because the <title> tag did not have a corresponding </title> tag.

Although te TOPICTITLE feature was accepted in 2014, it has not yet been added to the Foswiki core. I am still using my original code in foswiki.tmpl.
%TMPL:DEF{"topictitle"}% %IF{"defined TOPICTITLE" then="%TOPICTITLE%" else="%TOPIC%"}% %TMPL:END%
%TMPL:DEF{"webtitle"}% %FLEXWEBLIST{webs="%WEB%" format="$name"}% %TMPL:END%
%TMPL:DEF{"stdwindowtitle"}%<title>%TMPL:P{"titleaction"}% <nop>%BASETOPIC% %TMPL:P{"titlesep"}% %BASEWEB% %TMPL:P{"titlesep"}% <nop>%WIKITOOLNAME%</title>%TMPL:END%
%TMPL:DEF{"whwindowtitle"}%<title>%TMPL:P{"titleaction"}% %TMPL:P{"webtitle"}% </title>%TMPL:END%
%TMPL:DEF{"ttwindowtitle"}%<title>%TMPL:P{"titleaction"}%<nop>%TMPL:P{"topictitle"}% %TMPL:P{"titlesep"}% %TMPL:P{"webtitle"}% </title>%TMPL:END%
%TMPL:DEF{"windowtitle"}%%IF{"$TOPIC='WebHome'" then='%TMPL:P{"whwindowtitle"}%' else='%TMPL:P{"ttwindowtitle"}%'}%%TMPL:END% 

This has issues with single quotes. I'm guessing the problem is here:
%TMPL:DEF{"windowtitle"}%%IF{"$TOPIC='WebHome'" then='%TMPL:P{"whwindowtitle"}%' else='%TMPL:P{"ttwindowtitle"}%'}%%TMPL:END% 

as there are single quotes in the IF statement, but I can't see how to fix the problem. Can I use backslashes in templates? Nested double quotes?

SHould I file a bug report on embedded single quotes in variables that are evaluated in template code?

Test Case: http://wiki.baapt.org/bin/view/Sandbox/Item14217TestCase

-- VickiBrown - 15 Nov 2016

Hmmm... Apparently, TMPL:P does not require quotes around its content. It looks like I can use
%TMPL:DEF{"windowtitle"}%%IF{"$TOPIC='WebHome'" then="%TMPL:P{whwindowtitle}%" else="%TMPL:P{ttwindowtitle}%"}%%TMPL:END%

Does anyone disagree?

-- VickiBrown - 15 Nov 2016

I've checked the documentation, the Template.pm code and the unit tests. The documentation doesn't show any usage except for double quoted names, and that's also the only case tested in the unit tests. However the code doesn't appear to require quoting. The regexes though are a bit inconsistent.
  • /%TMPL\:INCLUDE\{[\s\"]*(.*?)[\"\s]*\}%/ Seems to allow space or double quotes, but no single quotes.
Other macros appear to use the Foswiki::Attrs parser, but in the 'unfriendly' configuration. So the following does not apply to templates:
As well as the default Foswiki syntax (parameter values double-quoted) this class also parses single-quoted values, unquoted spaceless values, spaces around the =, and commas as well as spaces separating values. The extended syntax has to be enabled by passing the $friendly parameter to new.

The unfriendly version supports double-quoted with arguments, or an unquoted string without any parameters.

So based upon your examples above, they are working because there are no examples using parameters. =%TMPL:P{"x" P="y"}% = for example would have to use double quotes.

Straying from the documented syntax is probably risky. If it's not documented, or covered by the unit tests, then there is higher odds that it could change. Given that though, simple templates, without any parameters are probably fine when unquoted.

-- GeorgeClark - 16 Nov 2016
 

QuestionForm edit

Subject Topic Markup Language and applications
Extension
Version Foswiki 2.1.2
Status Answered
Related Topics
Topic revision: r3 - 08 Dec 2016, 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