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/09/25 15:16:11 UTC
[2/4] incubator-freemarker git commit: Bug fixed: When setting the
new_builtin_resolver from Properties or the setSetting(String, String) API,
it didn't recognize the camel case form of the allowed_classes and
trusted_templates keywords, and throw except
Bug fixed: When setting the new_builtin_resolver from Properties or the setSetting(String, String) API, it didn't recognize the camel case form of the allowed_classes and trusted_templates keywords, and throw exception for them. Now allowedClasses and trustedTemplates can be used as well.
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/ee1e9221
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/ee1e9221
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/ee1e9221
Branch: refs/heads/2.3
Commit: ee1e9221a8c6ed41a07cb0df80c2cbad608ea5b6
Parents: 2d0b493
Author: ddekany <dd...@apache.org>
Authored: Mon Sep 18 13:15:33 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Mon Sep 18 13:15:33 2017 +0200
----------------------------------------------------------------------
src/main/java/freemarker/core/Configurable.java | 26 +++++++++++-------
src/manual/en_US/book.xml | 28 ++++++++++++++------
.../freemarker/template/ConfigurationTest.java | 24 +++++++++++++++++
3 files changed, 61 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ee1e9221/src/main/java/freemarker/core/Configurable.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/Configurable.java b/src/main/java/freemarker/core/Configurable.java
index 492282a..0ae1be4 100644
--- a/src/main/java/freemarker/core/Configurable.java
+++ b/src/main/java/freemarker/core/Configurable.java
@@ -2033,8 +2033,10 @@ public class Configurable {
}
}
- private static final String ALLOWED_CLASSES = "allowed_classes";
- private static final String TRUSTED_TEMPLATES = "trusted_templates";
+ private static final String ALLOWED_CLASSES_SNAKE_CASE = "allowed_classes";
+ private static final String TRUSTED_TEMPLATES_SNAKE_CASE = "trusted_templates";
+ private static final String ALLOWED_CLASSES_CAMEL_CASE = "allowedClasses";
+ private static final String TRUSTED_TEMPLATES_CAMEL_CASE = "trustedTemplates";
/**
* Sets a FreeMarker setting by a name and string value. If you can configure FreeMarker directly with Java (or
@@ -2179,13 +2181,13 @@ public class Configurable {
* Use {@link TemplateClassResolver#UNRESTRICTED_RESOLVER}
* <li><p>{@code "safer"}:
* Use {@link TemplateClassResolver#SAFER_RESOLVER}
- * <li><p>{@code "allows_nothing"}:
+ * <li><p>{@code "allows_nothing"} (or {@code "allowsNothing"}):
* Use {@link TemplateClassResolver#ALLOWS_NOTHING_RESOLVER}
* <li><p>Something that contains colon will use
* {@link OptInTemplateClassResolver} and is expected to
* store comma separated values (possibly quoted) segmented
- * with {@code "allowed_classes:"} and/or
- * {@code "trusted_templates:"}. Examples of valid values:
+ * with {@code "allowed_classes:"} (or {@code "allowedClasses:"}) and/or
+ * {@code "trusted_templates:"} (or {@code "trustedTemplates:"}). Examples of valid values:
*
* <table style="width: auto; border-collapse: collapse" border="1"
* summary="trusted_template value examples">
@@ -2610,15 +2612,21 @@ public class Configurable {
KeyValuePair kv = (KeyValuePair) segments.get(i);
String segmentKey = (String) kv.getKey();
List segmentValue = (List) kv.getValue();
- if (segmentKey.equals(ALLOWED_CLASSES)) {
+ if (segmentKey.equals(ALLOWED_CLASSES_SNAKE_CASE)
+ || segmentKey.equals(ALLOWED_CLASSES_CAMEL_CASE)) {
allowedClasses = new HashSet(segmentValue);
- } else if (segmentKey.equals(TRUSTED_TEMPLATES)) {
+ } else if (segmentKey.equals(TRUSTED_TEMPLATES_SNAKE_CASE)
+ || segmentKey.equals(TRUSTED_TEMPLATES_CAMEL_CASE)) {
trustedTemplates = segmentValue;
} else {
throw new ParseException(
"Unrecognized list segment key: " + StringUtil.jQuote(segmentKey) +
- ". Supported keys are: \"" + ALLOWED_CLASSES + "\", \"" +
- TRUSTED_TEMPLATES + "\"", 0, 0);
+ ". Supported keys are: " +
+ "\"" + ALLOWED_CLASSES_SNAKE_CASE + "\", " +
+ "\"" + ALLOWED_CLASSES_CAMEL_CASE + "\", " +
+ "\"" + TRUSTED_TEMPLATES_SNAKE_CASE + "\", " +
+ "\"" + TRUSTED_TEMPLATES_CAMEL_CASE + "\". ",
+ 0, 0);
}
}
setNewBuiltinClassResolver(
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ee1e9221/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 569cbac..210f674 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -27181,24 +27181,36 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
<listitem>
<para>When logging error due to an error in an <link
linkend="ref.directive.attempt"><literal>attempt</literal>
- directive</link> block, the log message now indicates that error
- was inside an <literal>attempt</literal> block.</para>
+ directive</link> block, the log message now indicates that the
+ error was inside an <literal>attempt</literal> block.</para>
</listitem>
<listitem>
<para>Bug fixed (<link
xlink:href="https://issues.apache.org/jira/browse/FREEMARKER-52">FREEMARKER-52</link>):
- When setting the <literal>output_format</literal> with
- <literal>Properties</literal>, the
- <literal>XHTMLOutputFormat</literal> abbreviation wasn't
- recognized (for example in a <literal>.properties</literal>
- file, <literal>output_format=XHTMLOutputFormat</literal> didn't
- work, only
+ When setting the <literal>output_format</literal> from
+ <literal>Properties</literal> or the <literal>setSetting(String,
+ String)</literal> API, the <literal>XHTMLOutputFormat</literal>
+ abbreviation wasn't recognized (for example in a
+ <literal>.properties</literal> file,
+ <literal>output_format=XHTMLOutputFormat</literal> didn't work,
+ only
<literal>output_format=freemarker.core.XHTMLOutputFormat()</literal>
did).</para>
</listitem>
<listitem>
+ <para>Bug fixed: When setting the
+ <literal>new_builtin_resolver</literal> from
+ <literal>Properties</literal> or the <literal>setSetting(String,
+ String)</literal> API, it didn't recognize the camel case form
+ of the <literal>allowed_classes</literal> and
+ <literal>trusted_templates</literal> keywords, and throw
+ exception for them. Now <literal>allowedClasses</literal> and
+ <literal>trustedTemplates</literal> can be used as well.</para>
+ </listitem>
+
+ <listitem>
<para><literal>Constants.EMPTY_HASH</literal> and
<literal>GeneralPurposeNothing</literal> (the value of
<literal>missingVar!</literal>) now implements
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ee1e9221/src/test/java/freemarker/template/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/template/ConfigurationTest.java b/src/test/java/freemarker/template/ConfigurationTest.java
index 226306f..69eaf3a 100644
--- a/src/test/java/freemarker/template/ConfigurationTest.java
+++ b/src/test/java/freemarker/template/ConfigurationTest.java
@@ -66,9 +66,11 @@ import freemarker.core.EpochMillisTemplateDateFormatFactory;
import freemarker.core.HTMLOutputFormat;
import freemarker.core.HexTemplateNumberFormatFactory;
import freemarker.core.MarkupOutputFormat;
+import freemarker.core.OptInTemplateClassResolver;
import freemarker.core.OutputFormat;
import freemarker.core.ParseException;
import freemarker.core.RTFOutputFormat;
+import freemarker.core.TemplateClassResolver;
import freemarker.core.TemplateDateFormatFactory;
import freemarker.core.TemplateNumberFormatFactory;
import freemarker.core.UndefinedOutputFormat;
@@ -1694,6 +1696,28 @@ public class ConfigurationTest extends TestCase {
assertTrue(cfg.isTimeZoneExplicitlySet());
}
+ public void testNewBuiltinClassResolverSetting() throws TemplateException {
+ Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
+ assertSame(TemplateClassResolver.UNRESTRICTED_RESOLVER, cfg.getNewBuiltinClassResolver());
+
+ cfg.setSetting(Configuration.NEW_BUILTIN_CLASS_RESOLVER_KEY_SNAKE_CASE,
+ "allowed_classes: com.example.C1, com.example.C2, trusted_templates: lib/*, safe.ftl");
+ assertThat(cfg.getNewBuiltinClassResolver(), instanceOf(OptInTemplateClassResolver.class));
+
+ cfg.setSetting(Configuration.NEW_BUILTIN_CLASS_RESOLVER_KEY_SNAKE_CASE, "safer");
+ assertSame(TemplateClassResolver.SAFER_RESOLVER, cfg.getNewBuiltinClassResolver());
+
+ cfg.setSetting(Configuration.NEW_BUILTIN_CLASS_RESOLVER_KEY_CAMEL_CASE,
+ "allowedClasses: com.example.C1, com.example.C2, trustedTemplates: lib/*, safe.ftl");
+ assertThat(cfg.getNewBuiltinClassResolver(), instanceOf(OptInTemplateClassResolver.class));
+
+ cfg.setSetting(Configuration.NEW_BUILTIN_CLASS_RESOLVER_KEY_SNAKE_CASE, "allowsNothing");
+ assertSame(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER, cfg.getNewBuiltinClassResolver());
+
+ cfg.setSetting(Configuration.NEW_BUILTIN_CLASS_RESOLVER_KEY_SNAKE_CASE, "allows_nothing");
+ assertSame(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER, cfg.getNewBuiltinClassResolver());
+ }
+
@Test
public void testGetSettingNamesAreSorted() throws Exception {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);