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 Commit: f933ed03db875aa1f550e091339da6469e8cd6ba Parents: 304df82 Author: ddekany <ddek...@apache.org> Authored: Wed Jun 28 11:29:28 2017 +0200 Committer: ddekany <ddek...@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 : "&" | "&&" | "&&" | "\\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} <#-- Prints 2 --> <literal><#if (x > y)></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>&gt;</literal> and - <literal>&lt;</literal> on the place of the problematic - relation marks, like in: <literal><#if x &gt; - y></literal> or <literal><#if x &gt;= - y></literal> . Note that in general FTL does not support - entity references (the - <literal>&<replaceable>...</replaceable>;</literal> - things) in FTL tags; it's just an exception with the - arithmetical comparisons.</para> - </listitem> + <itemizedlist> + <listitem> + <para><literal>&gt;</literal> and + <literal>&lt;</literal> can also be used, like in: + <literal><#if x &gt; y></literal> or <literal><#if + x &gt;= y></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>&<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} <#-- Prints 2 --> <#if <emphasis>!</emphasis>hot> <#-- here hot must be a boolean --> It's not hot. </#if></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>&&</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;</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>&<replaceable>...</replaceable>;</literal> things) + in FTL tags; it's just an exception with these operators.</para> + </listitem> + + <listitem> + <para>Deprecated forms: <literal>&</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>&&</literal> (logical <quote>and</quote>) + operator: <literal>\and</literal> and + <literal>&amp;&amp;</literal>. These are to work around + issues in applications where the template must be a valid XML + (<literal>&&</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;</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 && boolean5 /> +<@assert test=!(false && true) /> +<@assert test=boolean4 \and boolean5 /> +<@assert test=!(false \and true) /> <p>Now test list models:</p>