You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/06/28 09:29:40 UTC

incubator-freemarker git commit: Added alternative syntaxes for the && (logical and) operator: \and and & & . These are to work around issues in applications where the template must be a valid XML (&& is not valid XML/HTML, at most places), or wher

Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 304df82a7 -> f933ed03d


Added alternative syntaxes for the && (logical and) operator: \and and &&. These are to work around issues in applications where the template must be a valid XML (&& is not valid XML/HTML, at most places), or where the template entered is stored after XML or HTML escaping. Note that lonely &, and `and` without \ is not recognized for backward compatibility.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/f933ed03
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/f933ed03
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/f933ed03

Branch: refs/heads/2.3-gae
Commit: f933ed03db875aa1f550e091339da6469e8cd6ba
Parents: 304df82
Author: ddekany <dd...@apache.org>
Authored: Wed Jun 28 11:29:28 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Wed Jun 28 11:29:28 2017 +0200

----------------------------------------------------------------------
 src/main/javacc/FTL.jj                          |  2 +-
 src/manual/en_US/book.xml                       | 94 +++++++++++++++-----
 .../test/templatesuite/templates/boolean.ftl    |  4 +
 3 files changed, 77 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f933ed03/src/main/javacc/FTL.jj
----------------------------------------------------------------------
diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj
index c6a9d8b..75c7784 100644
--- a/src/main/javacc/FTL.jj
+++ b/src/main/javacc/FTL.jj
@@ -1251,7 +1251,7 @@ TOKEN:
     |
     <PERCENT : "%">
     |
-    <AND : "&" | "&&" >
+    <AND : "&" | "&&" | "&amp;&amp;" | "\\and" >
     |
     <OR : "|" | "||">
     |

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f933ed03/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index a4d63a1..05435b0 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -3457,30 +3457,29 @@ ${12 % -5} &lt;#-- Prints 2 --&gt;
           <literal>&lt;#if (x &gt; y)&gt;</literal>, although it's considered
           to be less elegant.</para>
 
-          <note>
-            <para>FreeMarker supports some other alternatives too, but these
-            are deprecated:</para>
+          <para>FreeMarker supports some more syntactical alternatives:</para>
 
-            <itemizedlist>
-              <listitem>
-                <para>Writing <literal>&amp;gt;</literal> and
-                <literal>&amp;lt;</literal> on the place of the problematic
-                relation marks, like in: <literal>&lt;#if x &amp;gt;
-                y&gt;</literal> or <literal>&lt;#if x &amp;gt;=
-                y&gt;</literal> . Note that in general FTL does not support
-                entity references (the
-                <literal>&amp;<replaceable>...</replaceable>;</literal>
-                things) in FTL tags; it's just an exception with the
-                arithmetical comparisons.</para>
-              </listitem>
+          <itemizedlist>
+            <listitem>
+              <para><literal>&amp;gt;</literal> and
+              <literal>&amp;lt;</literal> can also be used, like in:
+              <literal>&lt;#if x &amp;gt; y&gt;</literal> or <literal>&lt;#if
+              x &amp;gt;= y&gt;</literal>. This isn't meant to be entered
+              manually; it's to work around cases where the template gets
+              XML/HTML escaped and the user can't easily prevent that
+              happening. Note that in general FTL does not support entity
+              references (the
+              <literal>&amp;<replaceable>...</replaceable>;</literal> things)
+              in FTL tags; it's just an exception with these operators.</para>
+            </listitem>
 
-              <listitem>
-                <para><literal>\lt</literal>, <literal>\lte</literal>,
-                <literal>\gt</literal> and <literal>\gte</literal> which are
-                the same as the ones without the backslash</para>
-              </listitem>
-            </itemizedlist>
-          </note>
+            <listitem>
+              <para>Deprecated forms: <literal>\lt</literal>,
+              <literal>\lte</literal>, <literal>\gt</literal> and
+              <literal>\gte</literal>. These are the same as the ones without
+              the backslash.</para>
+            </listitem>
+          </itemizedlist>
         </section>
 
         <section xml:id="dgui_template_exp_logicalop">
@@ -3535,6 +3534,38 @@ ${12 % -5} &lt;#-- Prints 2 --&gt;
 &lt;#if <emphasis>!</emphasis>hot&gt; &lt;#-- here hot must be a boolean --&gt;
   It's not hot.
 &lt;/#if&gt;</programlisting>
+
+          <para>FreeMarker supports some more syntactical alternatives:</para>
+
+          <itemizedlist>
+            <listitem>
+              <para><literal>\and</literal> (since FreeMarker 2.3.27): In some
+              applications using <literal>&amp;&amp;</literal> causes problems
+              as it's not valid in XML or HTML. While FreeMarker templates was
+              never intended to be valid XML/HTML, only their output should be
+              that, in reality there are some applications that expect the
+              template itself to be valid XML/HTML regardless. This syntax is
+              a workaround for such cases. Also note that unlike with the
+              comparison operators, <literal>and</literal> without
+              <literal>\</literal> is not supported due to backward
+              compatibility restrictions.</para>
+            </listitem>
+
+            <listitem>
+              <para><literal>&amp;amp;&amp;amp;</literal> (since FreeMarker
+              2.3.27): This isn't meant to be entered manually; it's to work
+              around cases where the template gets XML/HTML escaped and the
+              user can't easily prevent that happening. Note that in general
+              FTL does not support entity references (the
+              <literal>&amp;<replaceable>...</replaceable>;</literal> things)
+              in FTL tags; it's just an exception with these operators.</para>
+            </listitem>
+
+            <listitem>
+              <para>Deprecated forms: <literal>&amp;</literal> and
+              <literal>|</literal>. Don't use them anymore.</para>
+            </listitem>
+          </itemizedlist>
         </section>
 
         <section xml:id="dgui_template_exp_builtin">
@@ -26856,6 +26887,25 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
         accepted (graduated) Apache project.</para>
 
         <section>
+          <title>Changes on the FTL side</title>
+
+          <itemizedlist>
+            <listitem>
+              <para>Added alternative syntaxes for the
+              <literal>&amp;&amp;</literal> (logical <quote>and</quote>)
+              operator: <literal>\and</literal> and
+              <literal>&amp;amp;&amp;amp;</literal>. These are to work around
+              issues in applications where the template must be a valid XML
+              (<literal>&amp;&amp;</literal> is not valid XML/HTML, at most
+              places), or where the template entered is stored after XML or
+              HTML escaping. Note that lonely <literal>&amp;amp;</literal>,
+              and <literal>and</literal> without <literal>\</literal> is not
+              recognized for backward compatibility.</para>
+            </listitem>
+          </itemizedlist>
+        </section>
+
+        <section>
           <title>Changes on the Java side</title>
 
           <itemizedlist>

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f933ed03/src/test/resources/freemarker/test/templatesuite/templates/boolean.ftl
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/test/templatesuite/templates/boolean.ftl b/src/test/resources/freemarker/test/templatesuite/templates/boolean.ftl
index ab11c64..a76d9b9 100644
--- a/src/test/resources/freemarker/test/templatesuite/templates/boolean.ftl
+++ b/src/test/resources/freemarker/test/templatesuite/templates/boolean.ftl
@@ -71,6 +71,10 @@
 <#else>
     boolean4 && boolean5 failed.<br />
 </#if></p>
+<@assert test=boolean4 &amp;&amp; boolean5 />
+<@assert test=!(false &amp;&amp; true) />
+<@assert test=boolean4 \and boolean5 />
+<@assert test=!(false \and true) />
  
 <p>Now test list models:</p>