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 2016/06/09 22:39:20 UTC

[2/2] incubator-freemarker git commit: Bug fixed: TemplateConfiguration.apply(Template) didn't merge the customDateFormats and customNumberFormats Map-s when they were set both in the Template and in the applied TemplateConfiguration, instead it just kep

Bug fixed: TemplateConfiguration.apply(Template) didn't merge the customDateFormats and customNumberFormats Map-s when they were set both in the Template and in the applied TemplateConfiguration, instead it just kept the value in the Template (just like with atomic setting values).


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

Branch: refs/heads/2.3-gae
Commit: f27c087a5e0e5c086698f0730fcd8c01971d07bb
Parents: abf4656
Author: ddekany <dd...@apache.org>
Authored: Fri Jun 10 00:39:07 2016 +0200
Committer: ddekany <dd...@apache.org>
Committed: Fri Jun 10 00:39:07 2016 +0200

----------------------------------------------------------------------
 .../freemarker/core/TemplateConfiguration.java     | 12 +++++++-----
 src/manual/en_US/book.xml                          | 17 ++++++++++++++++-
 .../freemarker/core/TemplateConfigurationTest.java | 11 +++++++++++
 3 files changed, 34 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f27c087a/src/main/java/freemarker/core/TemplateConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/TemplateConfiguration.java b/src/main/java/freemarker/core/TemplateConfiguration.java
index b6ae122..06f5d7b 100644
--- a/src/main/java/freemarker/core/TemplateConfiguration.java
+++ b/src/main/java/freemarker/core/TemplateConfiguration.java
@@ -295,11 +295,13 @@ public final class TemplateConfiguration extends Configurable implements ParserC
         if (isClassicCompatibleSet() && !template.isClassicCompatibleSet()) {
             template.setClassicCompatibleAsInt(getClassicCompatibleAsInt());
         }
-        if (isCustomDateFormatsSet() && !template.isCustomDateFormatsSet()) {
-            template.setCustomDateFormats(getCustomDateFormats());
+        if (isCustomDateFormatsSet()) {
+            template.setCustomDateFormats(
+                    mergeMaps(getCustomDateFormats(), template.getCustomDateFormatsWithoutFallback(), false));
         }
-        if (isCustomNumberFormatsSet() && !template.isCustomNumberFormatsSet()) {
-            template.setCustomNumberFormats(getCustomNumberFormats());
+        if (isCustomNumberFormatsSet()) {
+            template.setCustomNumberFormats(
+                    mergeMaps(getCustomNumberFormats(), template.getCustomNumberFormatsWithoutFallback(), false));
         }
         if (isDateFormatSet() && !template.isDateFormatSet()) {
             template.setDateFormat(getDateFormat());
@@ -620,7 +622,7 @@ public final class TemplateConfiguration extends Configurable implements ParserC
                 || isURLEscapingCharsetSet();
     }
     
-    private Map mergeMaps(Map m1, Map m2, boolean overwriteOverwritesOrder) {
+    private Map mergeMaps(Map m1, Map m2, boolean overwriteUpdatesOrder) {
         if (m1 == null) return m2;
         if (m2 == null) return m1;
         if (m1.isEmpty()) return m2 != null ? m2 : m1;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f27c087a/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 80fd268..97886d3 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -26556,7 +26556,7 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
       <title>Version history</title>
 
       <section xml:id="versions_2_3_25">
-        <title>2.3.25</title>
+        <title>2.3.25 (incubating)</title>
 
         <section>
           <title>Changes on the FTL side</title>
@@ -26694,6 +26694,21 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
             </listitem>
 
             <listitem>
+              <para>Bug fixed:
+              <literal>TemplateConfiguration.apply(Template)</literal> didn't
+              merge the <literal>customDateFormats</literal> and
+              <literal>customNumberFormats</literal> <literal>Map</literal>-s
+              when they were set both in the <literal>Template</literal> and
+              in the applied <literal>TemplateConfiguration</literal>, instead
+              it just kept the value in the <literal>Template</literal> (just
+              like with atomic setting values). Note that it was unlikely to
+              run into this bug, as usually you (or FreeMarker) create a
+              single merged <literal>TemplateConfiguration</literal> with
+              <literal>TemplateConfiguration.merge(TemplateConfiguration)</literal>
+              and then apply it on a fresh template.</para>
+            </listitem>
+
+            <listitem>
               <para>Removed FindBugs <literal>@SuppressFBWarnings</literal>
               annotations from the binary (<literal>freemarker.jar</literal>),
               as they have caused warnings like this when compiling dependant

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f27c087a/src/test/java/freemarker/core/TemplateConfigurationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/TemplateConfigurationTest.java b/src/test/java/freemarker/core/TemplateConfigurationTest.java
index 5dd3756..ee92492 100644
--- a/src/test/java/freemarker/core/TemplateConfigurationTest.java
+++ b/src/test/java/freemarker/core/TemplateConfigurationTest.java
@@ -496,6 +496,9 @@ public class TemplateConfigurationTest {
             tc.setBooleanFormat("Y,N");
             tc.setAutoImports(ImmutableMap.of("a", "a.ftl", "b", "b.ftl", "c", "c.ftl"));
             tc.setAutoIncludes(ImmutableList.of("i1.ftl", "i2.ftl", "i3.ftl"));
+            tc.setCustomNumberFormats(ImmutableMap.of(
+                    "a", HexTemplateNumberFormatFactory.INSTANCE,
+                    "b", LocaleSensitiveTemplateNumberFormatFactory.INSTANCE));
             
             tc.apply(t);
         }
@@ -510,6 +513,9 @@ public class TemplateConfigurationTest {
             tc.setBooleanFormat("J,N");
             tc.setAutoImports(ImmutableMap.of("b", "b2.ftl", "d", "d.ftl"));
             tc.setAutoIncludes(ImmutableList.of("i2.ftl", "i4.ftl"));
+            tc.setCustomNumberFormats(ImmutableMap.of(
+                    "b", BaseNTemplateNumberFormatFactory.INSTANCE,
+                    "c", BaseNTemplateNumberFormatFactory.INSTANCE));
             
             tc.apply(t);
         }
@@ -517,6 +523,11 @@ public class TemplateConfigurationTest {
         assertEquals(ImmutableMap.of("d", "d.ftl", "a", "a.ftl", "b", "b.ftl", "c", "c.ftl"), t.getAutoImports());
         assertEquals(ImmutableList.of("d", "a", "b", "c"), new ArrayList<String>(t.getAutoImports().keySet()));
         assertEquals(ImmutableList.of("i4.ftl", "i1.ftl", "i2.ftl", "i3.ftl"), t.getAutoIncludes());
+        assertEquals(ImmutableMap.of( //
+                "b", LocaleSensitiveTemplateNumberFormatFactory.INSTANCE, //
+                "c", BaseNTemplateNumberFormatFactory.INSTANCE, //
+                "a", HexTemplateNumberFormatFactory.INSTANCE), //
+                t.getCustomNumberFormats());
     }
 
     @Test