Skip to content

Commit 55ffb5e

Browse files
committed
Adjusted last merged PR: incompatibleImprovements 2.3.24 -> 2.3.34. Added more JUnit tests. Updated version history.
1 parent 69cf616 commit 55ffb5e

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

freemarker-core/src/main/java/freemarker/template/_VersionInts.java

+1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ private _VersionInts() {
4747
public static final int V_2_3_31 = Configuration.VERSION_2_3_31.intValue();
4848
public static final int V_2_3_32 = Configuration.VERSION_2_3_32.intValue();
4949
public static final int V_2_3_33 = Configuration.VERSION_2_3_33.intValue();
50+
public static final int V_2_3_34 = Configuration.VERSION_2_3_34.intValue();
5051
public static final int V_2_4_0 = Version.intValueFor(2, 4, 0);
5152
}

freemarker-core/src/main/javacc/freemarker/core/FTL.jj

+1-1
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ TOKEN:
944944
<ITEMS : <START_TAG> "items" (<BLANK>)+ <AS> <BLANK>> { handleTagSyntaxAndSwitch(matchedToken, FM_EXPRESSION); }
945945
|
946946
<SEP : <START_TAG> "sep" <CLOSE_TAG1>> {
947-
if (incompatibleImprovements >= _VersionInts.V_2_3_24) handleTagSyntaxAndSwitch(matchedToken, DEFAULT);
947+
if (incompatibleImprovements >= _VersionInts.V_2_3_34) handleTagSyntaxAndSwitch(matchedToken, DEFAULT);
948948
}
949949
|
950950
<FOREACH : <START_TAG> "for" ("e" | "E") "ach" <BLANK>> {

freemarker-core/src/test/java/freemarker/core/SepParsingBugTest.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,54 @@ public class SepParsingBugTest extends TemplateTest {
3131

3232
@Test
3333
public void testAutodetectTagSyntax() throws TemplateException, IOException {
34-
getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_24);
34+
getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_34);
3535
getConfiguration().setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX);
3636
assertOutput("<#list [1, 2] as i>${i}<#sep>, </#list>", "1, 2");
3737
assertOutput("[#list [1, 2] as i]${i}[#sep], [/#list]", "1, 2");
3838
assertOutput("<#list [1, 2] as i>${i}[#sep], </#list>", "1[#sep], 2[#sep], ");
3939
assertOutput("[#list [1, 2] as i]${i}<#sep>, [/#list]", "1<#sep>, 2<#sep>, ");
40+
assertOutput("[#list [1, 2] as i]${i}[sep], [/#list]", "1[sep], 2[sep], ");
41+
assertOutput("[#list [1, 2] as i]${i}<sep>, [/#list]", "1<sep>, 2<sep>, ");
4042
assertErrorContains("<#sep>", "#sep must be inside");
4143
assertErrorContains("[#sep]", "#sep must be inside");
4244
}
4345

4446
@Test
4547
public void testAngleBracketsTagSyntax() throws TemplateException, IOException {
46-
getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_24);
48+
getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_34);
4749
getConfiguration().setTagSyntax(Configuration.ANGLE_BRACKET_TAG_SYNTAX);
4850
assertOutput("<#list [1, 2] as i>${i}<#sep>, </#list>", "1, 2");
4951
assertOutput("[#list [1, 2] as i]${i!'-'}[#sep], [/#list]", "[#list [1, 2] as i]-[#sep], [/#list]");
5052
assertOutput("<#list [1, 2] as i>${i}[#sep], </#list>", "1[#sep], 2[#sep], ");
53+
assertOutput("<#list [1, 2] as i>${i}<sep>, </#list>", "1<sep>, 2<sep>, ");
54+
assertOutput("<#list [1, 2] as i>${i}[sep], </#list>", "1[sep], 2[sep], ");
5155
assertErrorContains("[#list [1, 2] as i]${i}<#sep>, [/#list]", "#sep must be inside");
5256
assertErrorContains("<#sep>", "#sep must be inside");
5357
assertOutput("[#sep]", "[#sep]");
5458
}
5559

5660
@Test
5761
public void testSquareBracketTagSyntax() throws TemplateException, IOException {
58-
getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_24);
62+
getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_34);
5963
getConfiguration().setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
6064
assertOutput("<#list [1, 2] as i>${i!'-'}<#sep>, </#list>", "<#list [1, 2] as i>-<#sep>, </#list>");
6165
assertOutput("[#list [1, 2] as i]${i}[#sep], [/#list]", "1, 2");
6266
assertErrorContains("<#list [1, 2] as i>${i}[#sep], </#list>", "#sep must be inside");
6367
assertOutput("[#list [1, 2] as i]${i}<#sep>, [/#list]", "1<#sep>, 2<#sep>, ");
68+
assertOutput("[#list [1, 2] as i]${i}[sep], [/#list]", "1[sep], 2[sep], ");
69+
assertOutput("[#list [1, 2] as i]${i}<sep>, [/#list]", "1<sep>, 2<sep>, ");
6470
assertOutput("<#sep>", "<#sep>");
6571
assertErrorContains("[#sep]", "#sep must be inside");
6672
}
6773

6874
@Test
69-
public void testLegacyTagSyntax() throws TemplateException, IOException {
70-
getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_23);
75+
public void testPre2Dot3Dot34BugRecreated() throws TemplateException, IOException {
76+
getConfiguration().setIncompatibleImprovements(Configuration.VERSION_2_3_33);
7177
getConfiguration().setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX);
7278
assertOutput("<#list [1, 2] as i>${i}<sep>, </#list>", "1, 2");
79+
assertOutput("<#list [1, 2] as i>${i}[#sep], </#list>", "1, 2");
80+
// square bracket tags were always "strict":
81+
assertOutput("[#list [1, 2] as i]${i}[sep], [/#list]", "1[sep], 2[sep], ");
82+
assertOutput("[#list [1, 2] as i]${i}<#sep>, [/#list]", "1, 2");
7383
}
7484
}

freemarker-manual/src/main/docgen/en_US/book.xml

+13-7
Original file line numberDiff line numberDiff line change
@@ -30458,7 +30458,7 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
3045830458
<section xml:id="versions_2_3_34">
3045930459
<title>2.3.34</title>
3046030460

30461-
<para>Release date: 2024-12-01 + release process</para>
30461+
<para>Release date: 2024-12-08 + release process</para>
3046230462

3046330463
<section>
3046430464
<title>Changes on the FTL side</title>
@@ -30501,13 +30501,19 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
3050130501
<listitem>
3050230502
<para><link
3050330503
xlink:href="https://github.com/apache/freemarker/pull/119">GitHub
30504-
PR-119</link>: Fixed bug: Both <literal>[#sep]</literal> and
30505-
<literal>&lt;#sep&gt;</literal> were interpreted as a call to
30504+
PR-119</link>: Fixed bug if you set the <link
30505+
linkend="pgui_config_incompatible_improvements_how_to_set"><literal>incompatible_improvements</literal>
30506+
setting</link> to 2.3.34 or higher: Both
30507+
<literal>[#sep]</literal>, <literal>&lt;#sep&gt;</literal>, and
30508+
<literal>&lt;sep&gt;</literal> were all interpreted as a call to
3050630509
the <literal>sep</literal> directive, regardless if the already
30507-
established tag syntax was angle bracket or square bracket tags.
30508-
For now on, the tag will be seen as just static text, if the
30509-
opposite tag syntax was already established, just as it's done
30510-
for all other FTL tags.</para>
30510+
established tag syntax was angle bracket or square bracket tags,
30511+
or if the tag syntax was <quote>strict</quote> (requiring
30512+
<literal>#</literal>) or not. With this fix enabled via
30513+
<literal>incompatible_improvements</literal>, a
30514+
<literal>sep</literal> with the tag syntax that doesn't match
30515+
the configured/estabilished tag syntax will be seen as just
30516+
static text, just as it's done for any other FTL tags.</para>
3051130517
</listitem>
3051230518

3051330519
<listitem>

0 commit comments

Comments
 (0)