This is an automated email from the ASF dual-hosted git repository. ddekany pushed a commit to branch 2.3-gae in repository https://gitbox.apache.org/repos/asf/freemarker.git
commit 578106c8792b43254595998de0a8dea6fbbc6b16 Author: ddekany <[email protected]> AuthorDate: Sat Nov 30 19:55:18 2024 +0100 Post-merge adjustments for "Fix sep directive in syntax A breaks templates in syntax B": Added it to change log. Replaced JUnit test with one that covers more variations. --- .../src/test/java/freemarker/core/ListSepTest.java | 44 --------------- .../java/freemarker/core/SepParsingBugTest.java | 65 ++++++++++++++++++++++ freemarker-manual/src/main/docgen/en_US/book.xml | 10 ++++ 3 files changed, 75 insertions(+), 44 deletions(-) diff --git a/freemarker-core/src/test/java/freemarker/core/ListSepTest.java b/freemarker-core/src/test/java/freemarker/core/ListSepTest.java deleted file mode 100644 index cadf9af4..00000000 --- a/freemarker-core/src/test/java/freemarker/core/ListSepTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package freemarker.core; - -import freemarker.template.*; -import freemarker.test.TemplateTest; -import org.junit.Test; - -import java.io.IOException; - -public class ListSepTest extends TemplateTest { - - @Test - public void testAngleBracketSepDoesNotBreakSquareBracketTemplate() throws IOException, TemplateException { - assertOutput( - "<#list values as value>${value}<#sep>, </#list>'", - "<#list values as value>${value}<#sep>, </#list>'" - ); - } - - @Override - protected Configuration createConfiguration() throws Exception { - Configuration conf = super.createConfiguration(); - conf.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX); - conf.setInterpolationSyntax(Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX); - return conf; - } -} diff --git a/freemarker-core/src/test/java/freemarker/core/SepParsingBugTest.java b/freemarker-core/src/test/java/freemarker/core/SepParsingBugTest.java new file mode 100644 index 00000000..f85e841c --- /dev/null +++ b/freemarker-core/src/test/java/freemarker/core/SepParsingBugTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package freemarker.core; + +import java.io.IOException; + +import org.junit.Test; + +import freemarker.template.Configuration; +import freemarker.template.TemplateException; +import freemarker.test.TemplateTest; + +public class SepParsingBugTest extends TemplateTest { + + @Test + public void testAutodetectTagSyntax() throws TemplateException, IOException { + getConfiguration().setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX); + assertOutput("<#list [1, 2] as i>${i}<#sep>, </#list>", "1, 2"); + assertOutput("[#list [1, 2] as i]${i}[#sep], [/#list]", "1, 2"); + assertOutput("<#list [1, 2] as i>${i}[#sep], </#list>", "1[#sep], 2[#sep], "); + assertOutput("[#list [1, 2] as i]${i}<#sep>, [/#list]", "1<#sep>, 2<#sep>, "); + assertErrorContains("<#sep>", "#sep must be inside"); + assertErrorContains("[#sep]", "#sep must be inside"); + } + + @Test + public void testAngleBracketsTagSyntax() throws TemplateException, IOException { + getConfiguration().setTagSyntax(Configuration.ANGLE_BRACKET_TAG_SYNTAX); + assertOutput("<#list [1, 2] as i>${i}<#sep>, </#list>", "1, 2"); + assertOutput("[#list [1, 2] as i]${i!'-'}[#sep], [/#list]", "[#list [1, 2] as i]-[#sep], [/#list]"); + assertOutput("<#list [1, 2] as i>${i}[#sep], </#list>", "1[#sep], 2[#sep], "); + assertErrorContains("[#list [1, 2] as i]${i}<#sep>, [/#list]", "#sep must be inside"); + assertErrorContains("<#sep>", "#sep must be inside"); + assertOutput("[#sep]", "[#sep]"); + } + + @Test + public void testSquareBracketTagSyntax() throws TemplateException, IOException { + getConfiguration().setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX); + assertOutput("<#list [1, 2] as i>${i!'-'}<#sep>, </#list>", "<#list [1, 2] as i>-<#sep>, </#list>"); + assertOutput("[#list [1, 2] as i]${i}[#sep], [/#list]", "1, 2"); + assertErrorContains("<#list [1, 2] as i>${i}[#sep], </#list>", "#sep must be inside"); + assertOutput("[#list [1, 2] as i]${i}<#sep>, [/#list]", "1<#sep>, 2<#sep>, "); + assertOutput("<#sep>", "<#sep>"); + assertErrorContains("[#sep]", "#sep must be inside"); + } + +} diff --git a/freemarker-manual/src/main/docgen/en_US/book.xml b/freemarker-manual/src/main/docgen/en_US/book.xml index 2d19d252..80d04179 100644 --- a/freemarker-manual/src/main/docgen/en_US/book.xml +++ b/freemarker-manual/src/main/docgen/en_US/book.xml @@ -30494,6 +30494,16 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting> specified'}</literal>.</para> </listitem> + <listitem> + <para>Fixed bug: Both <literal>[#sep]</literal> and + <literal><#sep></literal> were interpreted as a call to + the <literal>sep</literal> directive, regardless if the already + established tag syntax was angle bracket or square bracket tags. + For now on, the tag will be seen as just static text, if the + opposite tag syntax was already established, just as it's done + for all other FTL tags.</para> + </listitem> + <listitem> <para><link xlink:href="https://issues.apache.org/jira/browse/FREEMARKER-227">FREEMARKER-227</link>:
