[1/2] incubator-freemarker git commit: Forward ported from 2.3-gae: Some more cleanup in FTL.jj
Repository: incubator-freemarker Updated Branches: refs/heads/3 6e61c1d60 -> 0d21cbb77 Forward ported from 2.3-gae: Some more cleanup in FTL.jj Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/348e73dc Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/348e73dc Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/348e73dc Branch: refs/heads/3 Commit: 348e73dc61f90af24ebe01e31b1db83a1b966517 Parents: 6e61c1d Author: ddekanyAuthored: Mon Mar 19 00:25:26 2018 +0100 Committer: ddekany Committed: Mon Mar 19 00:25:26 2018 +0100 -- .../core/InterpolationSyntaxTest.java | 1 + freemarker-core/src/main/javacc/FTL.jj | 35 +++- 2 files changed, 21 insertions(+), 15 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/348e73dc/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java -- diff --git a/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java b/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java index e6b0eeb..4d7d0cc 100644 --- a/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java +++ b/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java @@ -90,6 +90,7 @@ public class InterpolationSyntaxTest extends TemplateTest { assertErrorContains("[=", "end of file"); assertErrorContains("[=1", "unclosed \"[\""); +assertErrorContains("[=1}", "\"}\"", "open"); assertOutput("[='[\\=1]']", "[=1]"); assertOutput("[='[\\=1][=2]']", "12"); // Usual legacy interpolation escaping glitch... http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/348e73dc/freemarker-core/src/main/javacc/FTL.jj -- diff --git a/freemarker-core/src/main/javacc/FTL.jj b/freemarker-core/src/main/javacc/FTL.jj index 8da0768..76b32f5 100644 --- a/freemarker-core/src/main/javacc/FTL.jj +++ b/freemarker-core/src/main/javacc/FTL.jj @@ -527,7 +527,7 @@ TOKEN_MGR_DECLS: * Keeps track of how deeply nested we have the hash literals. This is necessary since we need to be able to * distinguish the } used to close a hash literal and the one used to close a ${ */ -private int hashLiteralNesting; +private int curlyBracketNesting; private int parenthesisNesting; private int bracketNesting; private boolean inFTLHeader; @@ -632,22 +632,21 @@ TOKEN_MGR_DECLS: SwitchTo(FM_EXPRESSION); } -/** - * @param tok - * Assumed to be an '}', or something that is the closing pair of another "mirror image" character. - */ -private void endInterpolation(Token tok) { +private void endInterpolation(Token closingTk) { if (postInterpolationLexState == -1) { -char c = tok.image.charAt(0); -throw new TokenMgrError( -"You can't have an \"" + c + "\" here, as there's nothing open that it could close.", -TokenMgrError.LEXICAL_ERROR, -tok.beginLine, tok.beginColumn, -tok.endLine, tok.endColumn); +throw newUnexpectedClosingTokenException(closingTk); } SwitchTo(postInterpolationLexState); postInterpolationLexState = -1; } + +private TokenMgrError newUnexpectedClosingTokenException(Token closingTk) { +return new TokenMgrError( +"You can't have an \"" + closingTk.image + "\" here, as there's nothing open that it could close.", +TokenMgrError.LEXICAL_ERROR, +closingTk.beginLine, closingTk.beginColumn, +closingTk.endLine, closingTk.endColumn); +} private void eatNewline() { int charsRead = 0; @@ -953,6 +952,7 @@ TOKEN: // Find related: [interpolation prefixes] { startInterpolation(matchedToken); } | +// Find related: [interpolation prefixes] { -++hashLiteralNesting; +++curlyBracketNesting; } | { -if (hashLiteralNesting == 0) endInterpolation(matchedToken); -else --hashLiteralNesting; +if (curlyBracketNesting > 0) { +--curlyBracketNesting; +} else if (interpolationSyntax != InterpolationSyntax.SQUARE_BRACKET) { +endInterpolation(matchedToken); +} else { +throw newUnexpectedClosingTokenException(matchedToken); +
[2/2] incubator-freemarker git commit: Forward ported from 2.3-gae: FTL.jj cleanup. Can't close with "]" when using angle bracket tag syntax anymore.
Forward ported from 2.3-gae: FTL.jj cleanup. Can't close with "]" when using angle bracket tag syntax anymore. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/0d21cbb7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/0d21cbb7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/0d21cbb7 Branch: refs/heads/3 Commit: 0d21cbb77004014654b6e7160ad7791939f0faad Parents: 348e73d Author: ddekanyAuthored: Mon Mar 19 23:42:35 2018 +0100 Committer: ddekany Committed: Mon Mar 19 23:42:35 2018 +0100 -- .../core/InterpolationSyntaxTest.java | 27 +-- .../core/ParsingErrorMessagesTest.java | 67 ++- .../freemarker/core/ASTExpStringLiteral.java| 3 +- freemarker-core/src/main/javacc/FTL.jj | 85 ++-- 4 files changed, 109 insertions(+), 73 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0d21cbb7/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java -- diff --git a/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java b/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java index 4d7d0cc..7dc0dd0 100644 --- a/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java +++ b/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java @@ -48,7 +48,10 @@ public class InterpolationSyntaxTest extends TemplateTest { assertOutput("${'a${1}#{2}b[=3]'}", "a1#{2}b[=3]"); assertOutput("<@r'${1} #{1} [=1]'?interpret />", "1 #{1} [=1]"); -assertOutput("${'\"${1} #{1} [=1]\"'?eval}", "1 #{1} [=1]"); +assertOutput("${'\"${1} #{1} [=1]\"'?eval}", "1 #{1} [=1]"); + +assertOutput("<#setting booleanFormat='y,n'>${2>1}", "y"); // Not an error since 2.3.28 +assertOutput("[#ftl][#setting booleanFormat='y,n']${2>1}", "y"); // Not an error since 2.3.28 } @Test @@ -94,7 +97,10 @@ public class InterpolationSyntaxTest extends TemplateTest { assertOutput("[='[\\=1]']", "[=1]"); assertOutput("[='[\\=1][=2]']", "12"); // Usual legacy interpolation escaping glitch... -assertOutput("[=r'[=1]']", "[=1]"); +assertOutput("[=r'[=1]']", "[=1]"); + +assertOutput("<#setting booleanFormat='y,n'>[=2>1]", "y"); +assertOutput("[#ftl][#setting booleanFormat='y,n'][=2>1]", "y"); StringWriter sw = new StringWriter(); new Template(null, "[= 1 + '[= 2 ]' ]", getConfiguration()).dump(sw); @@ -116,19 +122,28 @@ public class InterpolationSyntaxTest extends TemplateTest { } @Test -public void legacyTagSyntaxGlitchStillWorksTest() throws Exception { -String ftl = "<#if [true][0]]t<#else]f"; +String badFtl2 = "<#if true>OKhttp://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0d21cbb7/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java -- diff --git a/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java b/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java index bf729ea..962e7a9 100644 --- a/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java +++ b/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java @@ -19,19 +19,20 @@ package org.apache.freemarker.core; -import static org.junit.Assert.*; - import java.io.IOException; -import org.apache.freemarker.core.util._StringUtils; +import org.apache.freemarker.test.TemplateTest; import org.apache.freemarker.test.TestConfigurationBuilder; import org.junit.Test; -public class ParsingErrorMessagesTest { +public class ParsingErrorMessagesTest extends TemplateTest { -private Configuration cfg = new TestConfigurationBuilder() -.tagSyntax(TagSyntax.AUTO_DETECT) -.build(); +@Override +protected Configuration createDefaultConfiguration() throws Exception { +return new TestConfigurationBuilder() +.tagSyntax(TagSyntax.AUTO_DETECT) +.build(); +} @Test public void testNeedlessInterpolation() { @@ -122,10 +123,14 @@ public class ParsingErrorMessagesTest { } @Test -public void testInterpolatingClosingsErrors() { -assertErrorContains("${x", "unclosed"); +
incubator-freemarker git commit: (Minor internal renaming in FTL.jj)
Repository: incubator-freemarker Updated Branches: refs/heads/2.3-gae 01294537b -> 355a09a21 (Minor internal renaming in FTL.jj) Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/355a09a2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/355a09a2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/355a09a2 Branch: refs/heads/2.3-gae Commit: 355a09a21ee5daf514b1d90ef36751e0badf411a Parents: 0129453 Author: ddekanyAuthored: Mon Mar 19 23:37:45 2018 +0100 Committer: ddekany Committed: Mon Mar 19 23:37:45 2018 +0100 -- src/main/javacc/FTL.jj | 164 ++-- 1 file changed, 82 insertions(+), 82 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/355a09a2/src/main/javacc/FTL.jj -- diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj index 630ef39..d1ab33d 100644 --- a/src/main/javacc/FTL.jj +++ b/src/main/javacc/FTL.jj @@ -628,7 +628,7 @@ TOKEN_MGR_DECLS: boolean strictSyntaxMode, squBracTagSyntax, autodetectTagSyntax, -directiveSyntaxEstablished, +tagSyntaxEstablished, inInvocation; int interpolationSyntax; int initialNamingConvention; @@ -644,7 +644,7 @@ TOKEN_MGR_DECLS: // FreeMarker directives must start with <#. It also handles // tag syntax detection. If you update this logic, take a look // at the UNKNOWN_DIRECTIVE token too. -private void strictSyntaxCheck(Token tok, int tokenNamingConvention, int newLexState) { +private void handleTagSyntaxAndSwitch(Token tok, int tokenNamingConvention, int newLexState) { final String image = tok.image; // Non-strict syntax (deprecated) only supports legacy naming convention. @@ -657,7 +657,7 @@ TOKEN_MGR_DECLS: } char firstChar = image.charAt(0); -if (autodetectTagSyntax && !directiveSyntaxEstablished) { +if (autodetectTagSyntax && !tagSyntaxEstablished) { squBracTagSyntax = (firstChar == '['); } if ((firstChar == '[' && !squBracTagSyntax) || (firstChar == '<' && squBracTagSyntax)) { @@ -682,7 +682,7 @@ TOKEN_MGR_DECLS: } // We only get here if this is a strict FTL tag. -directiveSyntaxEstablished = true; +tagSyntaxEstablished = true; if (incompatibleImprovements >= _TemplateAPI.VERSION_INT_2_3_28 || interpolationSyntax == SQUARE_BRACKET_INTERPOLATION_SYNTAX) { @@ -751,8 +751,8 @@ TOKEN_MGR_DECLS: /** * Used for tags whose name isn't affected by naming convention. */ -private void strictSyntaxCheck(Token tok, int newLexState) { -strictSyntaxCheck(tok, Configuration.AUTO_DETECT_NAMING_CONVENTION, newLexState); +private void handleTagSyntaxAndSwitch(Token tok, int newLexState) { +handleTagSyntaxAndSwitch(tok, Configuration.AUTO_DETECT_NAMING_CONVENTION, newLexState); } private boolean isStrictTag(String image) { @@ -788,7 +788,7 @@ TOKEN_MGR_DECLS: private void unifiedCall(Token tok) { char firstChar = tok.image.charAt(0); -if (autodetectTagSyntax && !directiveSyntaxEstablished) { +if (autodetectTagSyntax && !tagSyntaxEstablished) { squBracTagSyntax = (firstChar == '['); } if (squBracTagSyntax && firstChar == '<') { @@ -799,7 +799,7 @@ TOKEN_MGR_DECLS: tok.kind = STATIC_TEXT_NON_WS; return; } -directiveSyntaxEstablished = true; +tagSyntaxEstablished = true; SwitchTo(NO_SPACE_EXPRESSION); } @@ -881,9 +881,9 @@ TOKEN_MGR_DECLS: } private void ftlHeader(Token matchedToken) { -if (!directiveSyntaxEstablished) { +if (!tagSyntaxEstablished) { squBracTagSyntax = matchedToken.image.charAt(0) == '['; -directiveSyntaxEstablished = true; +tagSyntaxEstablished = true; autodetectTagSyntax = false; } String img = matchedToken.image; @@ -918,168 +918,168 @@ TOKEN: /* * ATTENTION: Update _CoreAPI.*_BUILT_IN_DIRECTIVE_NAMES if you add new directives! */ - "attempt" > { strictSyntaxCheck(matchedToken, DEFAULT); } + "attempt" > { handleTagSyntaxAndSwitch(matchedToken, DEFAULT); } | - "recover" > { strictSyntaxCheck(matchedToken, DEFAULT); } + "recover" > { handleTagSyntaxAndSwitch(matchedToken, DEFAULT); } | - "if" > { strictSyntaxCheck(matchedToken, FM_EXPRESSION); } + "if" > {
[05/12] incubator-freemarker git commit: Added new ParserConfiguration setting, interpolation_syntax. It has 3 possible values:
Added new ParserConfiguration setting, interpolation_syntax. It has 3 possible values: - legacy (the default): Interpolations look like ${...} or #{...}. Note that #{...} is deprecated for a long time now. - dollar: Interpolations look like ${...}. With this syntax, #{...} will be just static text. - square_bracket: Interpolations look like [=...]. With this syntax ${...} and #{...} will be just static text. So it's useful if you generate output in a format where those (typically ${...}) are already used, such as to generate JSP pages, or to generate FreeMarker templates that use the default syntax. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/ca1ecf78 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/ca1ecf78 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/ca1ecf78 Branch: refs/heads/2.3 Commit: ca1ecf78e7eebdb83c2b147d5fb9aadb1c25f93a Parents: c630a41 Author: ddekanyAuthored: Fri Mar 16 00:36:31 2018 +0100 Committer: ddekany Committed: Fri Mar 16 00:36:31 2018 +0100 -- src/main/java/freemarker/core/Configurable.java | 7 +- .../LegacyConstructorParserConfiguration.java | 9 +- .../freemarker/core/ParserConfiguration.java| 7 + .../java/freemarker/core/StringLiteral.java | 14 +- .../freemarker/core/TemplateConfiguration.java | 27 ++ ..._ParserConfigurationWithInheritedFormat.java | 4 + .../java/freemarker/template/Configuration.java | 59 +++- .../java/freemarker/template/_TemplateAPI.java | 10 + src/main/javacc/FTL.jj | 116 +--- src/manual/en_US/book.xml | 276 ++- .../core/InterpolationSyntaxTest.java | 88 ++ .../core/TemplateConfigurationTest.java | 9 + .../freemarker/template/ConfigurationTest.java | 28 ++ 13 files changed, 542 insertions(+), 112 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ca1ecf78/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 f1a905b..a2b5d29 100644 --- a/src/main/java/freemarker/core/Configurable.java +++ b/src/main/java/freemarker/core/Configurable.java @@ -2365,7 +2365,12 @@ public class Configurable { * {@code "tag_syntax"}: * See {@link Configuration#setTagSyntax(int)}. * String value: Must be one of - * {@code "auto_detect"}, {@code "angle_bracket"}, and {@code "square_bracket"}. + * {@code "auto_detect"}, {@code "angle_bracket"}, and {@code "square_bracket"}. + * + * {@code "interpolation_syntax"} (since 2.3.28): + * See {@link Configuration#setInterpolationSyntax(int)}. + * String value: Must be one of + * {@code "legacy"}, {@code "dollar"}, and {@code "square_bracket"}. * * {@code "naming_convention"}: * See {@link Configuration#setNamingConvention(int)}. http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ca1ecf78/src/main/java/freemarker/core/LegacyConstructorParserConfiguration.java -- diff --git a/src/main/java/freemarker/core/LegacyConstructorParserConfiguration.java b/src/main/java/freemarker/core/LegacyConstructorParserConfiguration.java index 479af9a..a9a1e8e 100644 --- a/src/main/java/freemarker/core/LegacyConstructorParserConfiguration.java +++ b/src/main/java/freemarker/core/LegacyConstructorParserConfiguration.java @@ -28,6 +28,7 @@ import freemarker.template.Version; class LegacyConstructorParserConfiguration implements ParserConfiguration { private final int tagSyntax; +private final int interpolationSyntax; private final int namingConvention; private final boolean whitespaceStripping; private final boolean strictSyntaxMode; @@ -38,11 +39,13 @@ class LegacyConstructorParserConfiguration implements ParserConfiguration { private Integer tabSize; private final Version incompatibleImprovements; -public LegacyConstructorParserConfiguration(boolean strictSyntaxMode, boolean whitespaceStripping, int tagSyntax, +LegacyConstructorParserConfiguration(boolean strictSyntaxMode, boolean whitespaceStripping, +int tagSyntax, int interpolationSyntax, int namingConvention, Integer autoEscaping, OutputFormat outputFormat, Boolean recognizeStandardFileExtensions, Integer tabSize, Version incompatibleImprovements, ArithmeticEngine arithmeticEngine) { this.tagSyntax =
[10/12] incubator-freemarker git commit: (Some more cleanup in FTL.jj... as far as BC allows us)
(Some more cleanup in FTL.jj... as far as BC allows us) Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/f55f9d89 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/f55f9d89 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/f55f9d89 Branch: refs/heads/2.3 Commit: f55f9d8919aa7fce3b88af37ac55ea04eb701033 Parents: eacd516 Author: ddekanyAuthored: Mon Mar 19 00:24:15 2018 +0100 Committer: ddekany Committed: Mon Mar 19 00:24:15 2018 +0100 -- src/main/javacc/FTL.jj | 64 +++- .../core/InterpolationSyntaxTest.java | 1 + 2 files changed, 35 insertions(+), 30 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f55f9d89/src/main/javacc/FTL.jj -- diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj index d3be697..26f3368 100644 --- a/src/main/javacc/FTL.jj +++ b/src/main/javacc/FTL.jj @@ -116,29 +116,29 @@ public class FMParser { *The template associated with this parser. * @param reader *The character stream to use as input - * @param strictEscapeSyntax + * @param strictSyntaxMode *Whether FreeMarker directives must start with a # * * @Deprecated This is an internal API of FreeMarker; will be removed in 2.4. */ -public FMParser(Template template, Reader reader, boolean strictEscapeSyntax, boolean stripWhitespace) { -this(template, reader, strictEscapeSyntax, stripWhitespace, Configuration.AUTO_DETECT_TAG_SYNTAX); +public FMParser(Template template, Reader reader, boolean strictSyntaxMode, boolean stripWhitespace) { +this(template, reader, strictSyntaxMode, stripWhitespace, Configuration.AUTO_DETECT_TAG_SYNTAX); } /** * @Deprecated This is an internal API of FreeMarker; will be changed in 2.4. */ -public FMParser(Template template, Reader reader, boolean strictEscapeSyntax, boolean stripWhitespace, int tagSyntax) { -this(template, reader, strictEscapeSyntax, stripWhitespace, tagSyntax, +public FMParser(Template template, Reader reader, boolean strictSyntaxMode, boolean stripWhitespace, int tagSyntax) { +this(template, reader, strictSyntaxMode, stripWhitespace, tagSyntax, Configuration.PARSED_DEFAULT_INCOMPATIBLE_ENHANCEMENTS); } /** * @Deprecated This is an internal API of FreeMarker; will be changed in 2.4. */ -public FMParser(Template template, Reader reader, boolean strictEscapeSyntax, boolean stripWhitespace, +public FMParser(Template template, Reader reader, boolean strictSyntaxMode, boolean stripWhitespace, int tagSyntax, int incompatibleImprovements) { -this(template, reader, strictEscapeSyntax, stripWhitespace, +this(template, reader, strictSyntaxMode, stripWhitespace, tagSyntax, Configuration.AUTO_DETECT_NAMING_CONVENTION, incompatibleImprovements); } @@ -240,7 +240,7 @@ public class FMParser { token_source.setParser(this); -token_source.strictEscapeSyntax = pCfg.getStrictSyntaxMode(); +token_source.strictSyntaxMode = pCfg.getStrictSyntaxMode(); int tagSyntax = pCfg.getTagSyntax(); switch (tagSyntax) { @@ -287,7 +287,7 @@ public class FMParser { token_source.initialNamingConvention = parentTokenSource.initialNamingConvention; token_source.namingConvention = parentTokenSource.namingConvention; token_source.namingConventionEstabilisher = parentTokenSource.namingConventionEstabilisher; -token_source.SwitchTo(NODIRECTIVE); +token_source.SwitchTo(NO_DIRECTIVE); this.outputFormat = outputFormat; recalculateAutoEscapingField(); @@ -621,11 +621,11 @@ TOKEN_MGR_DECLS: * Keeps track of how deeply nested we have the hash literals. This is necessary since we need to be able to * distinguish the } used to close a hash literal and the one used to close a ${ */ -private int hashLiteralNesting; +private int curlyBracketNesting; private int parenthesisNesting; private int bracketNesting; private boolean inFTLHeader; -boolean strictEscapeSyntax, +boolean strictSyntaxMode, squBracTagSyntax, autodetectTagSyntax, directiveSyntaxEstablished, @@ -649,7 +649,7 @@ TOKEN_MGR_DECLS: // Non-strict syntax (deprecated) only supports legacy naming convention. // We didn't push this on the tokenizer because it made it slow, so
[02/12] incubator-freemarker git commit: Made it more clear that using Configuration.getVersion() for the value of the incompatibleImprovements setting is bad idea.
Made it more clear that using Configuration.getVersion() for the value of the incompatibleImprovements setting is bad idea. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/40ced2d4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/40ced2d4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/40ced2d4 Branch: refs/heads/2.3 Commit: 40ced2d45fcf92723e6db386e13df9161d5a4608 Parents: 1261610 Author: ddekanyAuthored: Tue Mar 13 08:11:25 2018 +0100 Committer: ddekany Committed: Tue Mar 13 08:11:25 2018 +0100 -- .../java/freemarker/template/Configuration.java | 19 +++--- src/manual/en_US/book.xml | 37 ++-- 2 files changed, 41 insertions(+), 15 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/40ced2d4/src/main/java/freemarker/template/Configuration.java -- diff --git a/src/main/java/freemarker/template/Configuration.java b/src/main/java/freemarker/template/Configuration.java index 3673272..5f35435 100644 --- a/src/main/java/freemarker/template/Configuration.java +++ b/src/main/java/freemarker/template/Configuration.java @@ -547,8 +547,8 @@ public class Configuration extends Configurable implements Cloneable, ParserConf * About the "incompatible improvements" setting * * This setting value is the FreeMarker version number where the not 100% backward compatible bug fixes and - * improvements that you want to enable were already implemented. In new projects you should set this to the - * version of FreeMarker that you start the development with. In older projects it's also usually better to keep + * improvements that you want to enable were already implemented. In new projects you should set this to the fixed + * FreeMarker version that you start the development with. In older projects it's also usually better to keep * this high, however you should check the changes activated (find them below), especially if not only the 3rd * version number (the micro version) of {@code incompatibleImprovements} is increased. Generally, as far as you * only increase the last version number of this setting, the changes are low risk. The default value is 2.3.0 to @@ -557,6 +557,9 @@ public class Configuration extends Configurable implements Cloneable, ParserConf * Bugfixes and improvements that are fully backward compatible, also those that are important security fixes, * are enabled regardless of the incompatible improvements setting. * + * Do NOT ever use {@link #getVersion()} to set the "incompatible improvements". Always use a fixed value, like + * {@link #VERSION_2_3_28}. Otherwise your application can break as you upgrade FreeMarker. + * * An important consequence of setting this setting is that now your application will check if the stated minimum * FreeMarker version requirement is met. Like if you set this setting to 2.3.22, but accidentally the application * is deployed with FreeMarker 2.3.21, then FreeMarker will fail, telling that a higher version is required. After @@ -1865,7 +1868,11 @@ public class Configuration extends Configurable implements Cloneable, ParserConf /** * Use {@link #Configuration(Version)} instead if possible; see the meaning of the parameter there. - * If the default value of a setting depends on the {@code incompatibleImprovements} and the value of that setting + * + * Do NOT ever use {@link #getVersion()} to set the "incompatible improvements". Always use a fixed value, like + * {@link #VERSION_2_3_28}. Otherwise your application can break as you upgrade FreeMarker. + * + * If the default value of a setting depends on the {@code incompatibleImprovements} and the value of that setting * was never set in this {@link Configuration} object through the public API, its value will be set to the default * value appropriate for the new {@code incompatibleImprovements}. (This adjustment of a setting value doesn't * count as setting that setting, so setting {@code incompatibleImprovements} for multiple times also works as @@ -3393,7 +3400,11 @@ public class Configuration extends Configurable implements Cloneable, ParserConf } /** - * Returns the FreeMarker version information, most importantly the major.minor.micro version numbers. + * Returns FreeMarker version information, most importantly the major.minor.micro version numbers; + * do NOT use this as the value of the {@code incompatible_improvements} setting (as the parameter to
[12/12] incubator-freemarker git commit: Merge remote-tracking branch 'origin/2.3-gae' into 2.3
Merge remote-tracking branch 'origin/2.3-gae' into 2.3 Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/edefaa2f Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/edefaa2f Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/edefaa2f Branch: refs/heads/2.3 Commit: edefaa2f6cdf00e1f979700b384f0b966873bde4 Parents: 0c69b19 0129453 Author: ddekanyAuthored: Mon Mar 19 22:21:23 2018 +0100 Committer: ddekany Committed: Mon Mar 19 22:21:23 2018 +0100 -- src/main/java/freemarker/core/Configurable.java | 7 +- .../java/freemarker/core/DollarVariable.java| 11 +- .../core/ExtendedDecimalFormatParser.java | 5 +- .../LegacyConstructorParserConfiguration.java | 9 +- .../java/freemarker/core/NumericalOutput.java | 5 +- .../freemarker/core/ParserConfiguration.java| 7 + .../java/freemarker/core/StringLiteral.java | 14 +- .../freemarker/core/TemplateConfiguration.java | 27 ++ ..._ParserConfigurationWithInheritedFormat.java | 4 + .../ext/beans/OverloadedNumberUtil.java | 2 +- .../java/freemarker/template/Configuration.java | 81 +++- src/main/java/freemarker/template/Template.java | 22 + .../java/freemarker/template/_TemplateAPI.java | 14 +- .../freemarker/template/utility/StringUtil.java | 22 +- src/main/javacc/FTL.jj | 258 +++ src/manual/en_US/book.xml | 440 +++ .../core/InterpolationSyntaxTest.java | 154 +++ .../core/ParsingErrorMessagesTest.java | 66 +-- .../core/TemplateConfigurationTest.java | 9 + .../freemarker/template/ConfigurationTest.java | 70 +++ .../template/utility/StringUtilTest.java| 24 + .../templates/string-builtins3.ftl | 4 +- 22 files changed, 1015 insertions(+), 240 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/edefaa2f/src/main/java/freemarker/template/Template.java --
[06/12] incubator-freemarker git commit: Changed Configuration.xxx_INTERPOLATION_SYNTAX int values so that they don't overlap with ..._TAG_SYNTAX values. Also, added test case to ConfigurationTest for
Changed Configuration.xxx_INTERPOLATION_SYNTAX int values so that they don't overlap with ..._TAG_SYNTAX values. Also, added test case to ConfigurationTest for tag_syntax, fixing incorrect error message along the way. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/eb6781b4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/eb6781b4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/eb6781b4 Branch: refs/heads/2.3 Commit: eb6781bd774c536f3da235972f1c34cd68bd Parents: ca1ecf7 Author: ddekanyAuthored: Fri Mar 16 18:46:11 2018 +0100 Committer: ddekany Committed: Fri Mar 16 18:46:11 2018 +0100 -- .../java/freemarker/template/Configuration.java | 6 +-- .../java/freemarker/template/_TemplateAPI.java | 4 +- .../freemarker/template/ConfigurationTest.java | 44 +++- 3 files changed, 48 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eb6781b4/src/main/java/freemarker/template/Configuration.java -- diff --git a/src/main/java/freemarker/template/Configuration.java b/src/main/java/freemarker/template/Configuration.java index 34b055e..53fcd49 100644 --- a/src/main/java/freemarker/template/Configuration.java +++ b/src/main/java/freemarker/template/Configuration.java @@ -381,11 +381,11 @@ public class Configuration extends Configurable implements Cloneable, ParserConf public static final int SQUARE_BRACKET_TAG_SYNTAX = 2; /** ${expression} and the deprecated #{expression; numFormat} @since 2.3.28 */ -public static final int LEGACY_INTERPOLATION_SYNTAX = 0; +public static final int LEGACY_INTERPOLATION_SYNTAX = 20; /** ${expression} only (not #{expression; numFormat}) @since 2.3.28 */ -public static final int DOLLAR_INTERPOLATION_SYNTAX = 1; +public static final int DOLLAR_INTERPOLATION_SYNTAX = 21; /** [=expression] @since 2.3.28 */ -public static final int SQUARE_BRACKET_INTERPOLATION_SYNTAX = 2; +public static final int SQUARE_BRACKET_INTERPOLATION_SYNTAX = 22; public static final int AUTO_DETECT_NAMING_CONVENTION = 10; public static final int LEGACY_NAMING_CONVENTION = 11; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eb6781b4/src/main/java/freemarker/template/_TemplateAPI.java -- diff --git a/src/main/java/freemarker/template/_TemplateAPI.java b/src/main/java/freemarker/template/_TemplateAPI.java index 9b2c22d..124677a 100644 --- a/src/main/java/freemarker/template/_TemplateAPI.java +++ b/src/main/java/freemarker/template/_TemplateAPI.java @@ -154,8 +154,8 @@ public class _TemplateAPI { && tagSyntax != Configuration.SQUARE_BRACKET_TAG_SYNTAX && tagSyntax != Configuration.ANGLE_BRACKET_TAG_SYNTAX) { throw new IllegalArgumentException("\"tag_syntax\" can only be set to one of these: " -+ "Configuration.AUTO_DETECT_TAG_SYNTAX, Configuration.ANGLE_BRACKET_SYNTAX, " -+ "or Configuration.SQUARE_BRACKET_SYNTAX"); ++ "Configuration.AUTO_DETECT_TAG_SYNTAX, Configuration.ANGLE_BRACKET_TAG_SYNTAX, " ++ "or Configuration.SQUARE_BRACKET_TAG_SYNTAX"); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eb6781b4/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 fa6b508..72c1291 100644 --- a/src/test/java/freemarker/template/ConfigurationTest.java +++ b/src/test/java/freemarker/template/ConfigurationTest.java @@ -1616,6 +1616,41 @@ public class ConfigurationTest extends TestCase { assertEquals(Configuration.AUTO_DETECT_NAMING_CONVENTION, cfg.getNamingConvention()); } +public void testTagSyntaxSetting() throws TemplateException { +Configuration cfg = new Configuration(Configuration.VERSION_2_3_28); + +// Default is "angle brackets": +assertEquals(Configuration.ANGLE_BRACKET_TAG_SYNTAX, cfg.getTagSyntax()); + +cfg.setSetting("tag_syntax", "angle_bracket"); +assertEquals(Configuration.ANGLE_BRACKET_TAG_SYNTAX, cfg.getTagSyntax()); + +cfg.setSetting("tag_syntax", "square_bracket"); +assertEquals(Configuration.SQUARE_BRACKET_TAG_SYNTAX, cfg.getTagSyntax()); + +cfg.setSetting("tag_syntax", "auto_detect"); +
[01/12] incubator-freemarker git commit: Version history additions
Repository: incubator-freemarker Updated Branches: refs/heads/2.3 0c69b1983 -> edefaa2f6 Version history additions Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/12616107 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/12616107 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/12616107 Branch: refs/heads/2.3 Commit: 12616107209fd8d898c25efff8b7d5192a9f3c4e Parents: 0c77097 Author: ddekanyAuthored: Mon Mar 12 08:04:59 2018 +0100 Committer: ddekany Committed: Mon Mar 12 08:04:59 2018 +0100 -- src/manual/en_US/book.xml | 13 + 1 file changed, 13 insertions(+) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/12616107/src/manual/en_US/book.xml -- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index 4b89a2f..3bd2562 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -27531,6 +27531,14 @@ TemplateModel x = env.getVariable("x"); // get variable x + Avoided possible performance bottleneck when executing + templates on many threads, caused be that + java.beans.PropertyDescriptor.getReadMethod() + is synchronized (https://issues.apache.org/jira/browse/FREEMARKER-80;>FREEMARKER-80). + + + Added TemplateModelUtils.getKeyValuePairIterator(TemplateHashModelEx) static utility class, which can be used to get a @@ -27550,6 +27558,11 @@ TemplateModel x = env.getVariable("x"); // get variable x it unwraps into a LinkedHashMap instead of into a plain HashMap. + + + freemarker.ext.beans.HashAdapter.size() + was overridden for better performance. +
[03/12] incubator-freemarker git commit: Fixed incorrect listing of valid roundingMode-s in extended Java decimal format parsing error message
Fixed incorrect listing of valid roundingMode-s in extended Java decimal format parsing error message Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/54bd25b0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/54bd25b0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/54bd25b0 Branch: refs/heads/2.3 Commit: 54bd25b0ec51f40ba6e231edf21bef56aa6a8330 Parents: 40ced2d Author: ddekanyAuthored: Tue Mar 13 09:41:35 2018 +0100 Committer: ddekany Committed: Tue Mar 13 09:41:35 2018 +0100 -- .../java/freemarker/core/ExtendedDecimalFormatParser.java | 5 - src/manual/en_US/book.xml | 7 +++ 2 files changed, 11 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/54bd25b0/src/main/java/freemarker/core/ExtendedDecimalFormatParser.java -- diff --git a/src/main/java/freemarker/core/ExtendedDecimalFormatParser.java b/src/main/java/freemarker/core/ExtendedDecimalFormatParser.java index c31171b..0c3286a 100644 --- a/src/main/java/freemarker/core/ExtendedDecimalFormatParser.java +++ b/src/main/java/freemarker/core/ExtendedDecimalFormatParser.java @@ -80,7 +80,10 @@ class ExtendedDecimalFormatParser { } else if (value.equals(PARAM_VALUE_RND_UNNECESSARY)) { parsedValue = RoundingMode.UNNECESSARY; } else { -throw new InvalidParameterValueException("Should be one of: u, d, c, f, hd, he, hu, un"); +throw new InvalidParameterValueException("Should be one of: " ++ PARAM_VALUE_RND_UP + ", " + PARAM_VALUE_RND_DOWN + ", " + PARAM_VALUE_RND_CEILING + ", " ++ PARAM_VALUE_RND_FLOOR + ", " + PARAM_VALUE_RND_HALF_DOWN + ", " ++ PARAM_VALUE_RND_HALF_EVEN + ", " + PARAM_VALUE_RND_UNNECESSARY); } if (_JavaVersions.JAVA_6 == null) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/54bd25b0/src/manual/en_US/book.xml -- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index 3d8e321..231b607 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -27578,6 +27578,13 @@ TemplateModel x = env.getVariable("x"); // get variable x freemarker.ext.beans.HashAdapter.size() was overridden for better performance. + + + Fixed incorrect listing of valid + roundingMode-s in extended Java decimal + format parsing error message +
[09/12] incubator-freemarker git commit: Cleanup related to [=...], also some missing functionality added.
Cleanup related to [=...], also some missing functionality added. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/eacd5168 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/eacd5168 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/eacd5168 Branch: refs/heads/2.3 Commit: eacd51689fb301d4d128bc26dd9e96781474fd89 Parents: df4dc52 Author: ddekanyAuthored: Sun Mar 18 18:37:23 2018 +0100 Committer: ddekany Committed: Sun Mar 18 18:37:23 2018 +0100 -- .../java/freemarker/core/DollarVariable.java| 11 -- .../java/freemarker/core/NumericalOutput.java | 5 ++- .../java/freemarker/core/StringLiteral.java | 6 +-- .../ext/beans/OverloadedNumberUtil.java | 2 +- .../java/freemarker/template/Configuration.java | 3 +- src/main/java/freemarker/template/Template.java | 22 +++ src/main/javacc/FTL.jj | 41 .../core/InterpolationSyntaxTest.java | 8 8 files changed, 64 insertions(+), 34 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eacd5168/src/main/java/freemarker/core/DollarVariable.java -- diff --git a/src/main/java/freemarker/core/DollarVariable.java b/src/main/java/freemarker/core/DollarVariable.java index 7e7bd1f..12fa02a 100644 --- a/src/main/java/freemarker/core/DollarVariable.java +++ b/src/main/java/freemarker/core/DollarVariable.java @@ -22,11 +22,15 @@ package freemarker.core; import java.io.IOException; import java.io.Writer; +import freemarker.template.Configuration; import freemarker.template.TemplateException; import freemarker.template.utility.StringUtil; /** - * An instruction that outputs the value of an Expression. + * An interpolation like ${exp} or {@code [=exp]}. The class name is the remnant of old times, but as + * some users are using the package-visible AST API, it wasn't renamed. + * + * @see NumericalOutput */ final class DollarVariable extends Interpolation { @@ -99,10 +103,11 @@ final class DollarVariable extends Interpolation { @Override protected String dump(boolean canonical, boolean inStringLiteral) { StringBuilder sb = new StringBuilder(); -sb.append("${"); +int syntax = getTemplate().getInterpolationSyntax(); +sb.append(syntax != Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX ? "${" : "[="); final String exprCF = expression.getCanonicalForm(); sb.append(inStringLiteral ? StringUtil.FTLStringLiteralEnc(exprCF, '"') : exprCF); -sb.append("}"); +sb.append(syntax != Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX ? "}" : "]"); if (!canonical && expression != escapedExpression) { sb.append(" auto-escaped"); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eacd5168/src/main/java/freemarker/core/NumericalOutput.java -- diff --git a/src/main/java/freemarker/core/NumericalOutput.java b/src/main/java/freemarker/core/NumericalOutput.java index 08e8301..c897bd1 100644 --- a/src/main/java/freemarker/core/NumericalOutput.java +++ b/src/main/java/freemarker/core/NumericalOutput.java @@ -28,7 +28,10 @@ import freemarker.template.TemplateException; import freemarker.template.utility.StringUtil; /** - * An instruction that outputs the value of a numerical expression. + * An interpolation like #{numericalExp; format}; it's deprecated, but still supported. The class name is + * the remnant of old times, but as some users are using the package-visible AST API, it wasn't renamed. + * + * @see DollarVariable */ final class NumericalOutput extends Interpolation { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/eacd5168/src/main/java/freemarker/core/StringLiteral.java -- diff --git a/src/main/java/freemarker/core/StringLiteral.java b/src/main/java/freemarker/core/StringLiteral.java index 6d53c17..c116498 100644 --- a/src/main/java/freemarker/core/StringLiteral.java +++ b/src/main/java/freemarker/core/StringLiteral.java @@ -54,9 +54,9 @@ final class StringLiteral extends Expression implements TemplateScalarModel { if (value.length() > 3 && ( (intSyn == Configuration.LEGACY_INTERPOLATION_SYNTAX || intSyn == Configuration.DOLLAR_INTERPOLATION_SYNTAX) -&& (value.indexOf("${") >= 0 -|| intSyn == Configuration.LEGACY_INTERPOLATION_SYNTAX && value.indexOf("#{") >= 0) -
[08/12] incubator-freemarker git commit: In string literals, \= is now a valid escape sequence, resulting in a =. This is useful when you are using the new [=exp] interpolation syntax, which can be es
In string literals, \= is now a valid escape sequence, resulting in a =. This is useful when you are using the new [=exp] interpolation syntax, which can be escaped in a string literal like "Literal [\=x]". (Also improved [=...] related documentation and test a bit.) Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/df4dc52f Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/df4dc52f Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/df4dc52f Branch: refs/heads/2.3 Commit: df4dc52f2f1799299a9455ac016dfecaecf9004b Parents: aeaafe5 Author: ddekanyAuthored: Fri Mar 16 23:58:29 2018 +0100 Committer: ddekany Committed: Fri Mar 16 23:58:29 2018 +0100 -- .../freemarker/template/utility/StringUtil.java | 22 +-- src/main/javacc/FTL.jj | 2 +- src/manual/en_US/book.xml | 67 +--- .../core/InterpolationSyntaxTest.java | 7 ++ .../template/utility/StringUtilTest.java| 24 +++ 5 files changed, 108 insertions(+), 14 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/df4dc52f/src/main/java/freemarker/template/utility/StringUtil.java -- diff --git a/src/main/java/freemarker/template/utility/StringUtil.java b/src/main/java/freemarker/template/utility/StringUtil.java index 33fe03b..a5156aa 100644 --- a/src/main/java/freemarker/template/utility/StringUtil.java +++ b/src/main/java/freemarker/template/utility/StringUtil.java @@ -38,6 +38,10 @@ import freemarker.template.Version; */ public class StringUtil { +/** + * Used to look up if the chars with low code needs to be escaped, but note that it gives bad result for '=', as + * there the it matters if it's after '['. + */ private static final char[] ESCAPES = createEscapes(); private static final char[] LT = new char[] { '&', 'l', 't', ';' }; @@ -426,6 +430,7 @@ public class StringUtil { escapes['\''] = '\''; escapes['"'] = '"'; escapes['<'] = 'l'; +// As '=' is only escaped if it's after '[', we can't handle it here escapes['>'] = 'g'; escapes['&'] = 'a'; escapes['\b'] = 'b'; @@ -480,10 +485,16 @@ public class StringUtil { StringBuilder buf = null; for (int i = 0; i < ln; i++) { char c = s.charAt(i); -char escape = -c < escLn ? ESCAPES[c] : -c == '{' && i > 0 && isInterpolationStart(s.charAt(i - 1)) ? '{' : -0; +char escape; +if (c == '=') { +escape = i > 0 && s.charAt(i - 1) == '[' ? '=' : 0; +} else if (c < escLn) { +escape = ESCAPES[c]; // +} else if (c == '{' && i > 0 && isInterpolationStart(s.charAt(i - 1))) { +escape = '{'; +} else { +escape = 0; +} if (escape == 0 || escape == otherQuotation) { if (buf != null) { buf.append(c); @@ -605,7 +616,8 @@ public class StringUtil { bidx = idx + 2; break; case '{': -buf.append('{'); +case '=': +buf.append(c); bidx = idx + 2; break; case 'x': { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/df4dc52f/src/main/javacc/FTL.jj -- diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj index f1fa595..4134b70 100644 --- a/src/main/javacc/FTL.jj +++ b/src/main/javacc/FTL.jj @@ -1194,7 +1194,7 @@ TOKEN: <#ESCAPED_CHAR : "\\" ( -("n" | "t" | "r" | "f" | "b" | "g" | "l" | "a" | "\\" | "'" | "\"" | "$" | "{") +("n" | "t" | "r" | "f" | "b" | "g" | "l" | "a" | "\\" | "'" | "\"" | "$" | "{" | "=") | ("x" ["0"-"9", "A"-"F", "a"-"f"]) ) http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/df4dc52f/src/manual/en_US/book.xml -- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index cbda1a8..ac58a2a 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -2276,6 +2276,13 @@ this is a backslash: \ + \= + + Equals character: = (Supported since + FreeMarker 2.3.28.) + + +
[07/12] incubator-freemarker git commit: Added some more interpolation_syntax tests
Added some more interpolation_syntax tests Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/aeaafe51 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/aeaafe51 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/aeaafe51 Branch: refs/heads/2.3 Commit: aeaafe5132fdd8fdde773b29d3584921b2f81d8d Parents: eb6781b Author: ddekanyAuthored: Fri Mar 16 18:48:51 2018 +0100 Committer: ddekany Committed: Fri Mar 16 18:48:51 2018 +0100 -- .../core/InterpolationSyntaxTest.java | 29 +++- 1 file changed, 28 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/aeaafe51/src/test/java/freemarker/core/InterpolationSyntaxTest.java -- diff --git a/src/test/java/freemarker/core/InterpolationSyntaxTest.java b/src/test/java/freemarker/core/InterpolationSyntaxTest.java index 3bd49be..c1721c8 100644 --- a/src/test/java/freemarker/core/InterpolationSyntaxTest.java +++ b/src/test/java/freemarker/core/InterpolationSyntaxTest.java @@ -16,6 +16,13 @@ public class InterpolationSyntaxTest extends TemplateTest { assertOutput( "${{'x': 1}['x']} #{{'x': 1}['x']} [={'x': 1}['x']]", "1 1 [={'x': 1}['x']]"); + +assertOutput("${'a[=1]b'}", "a[=1]b"); +assertOutput("${'a${1}#{2}b'}", "a12b"); +assertOutput("${'a${1}#{2}b[=3]'}", "a12b[=3]"); + +assertOutput("<@r'${1} #{1} [=1]'?interpret />", "1 1 [=1]"); +assertOutput("${'\"${1} #{1} [=1]\"'?eval}", "1 1 [=1]"); } @Test @@ -26,6 +33,13 @@ public class InterpolationSyntaxTest extends TemplateTest { assertOutput( "${{'x': 1}['x']} #{{'x': 1}['x']} [={'x': 1}['x']]", "1 #{{'x': 1}['x']} [={'x': 1}['x']]"); + +assertOutput("${'a[=1]b'}", "a[=1]b"); +assertOutput("${'a${1}#{2}b'}", "a1#{2}b"); +assertOutput("${'a${1}#{2}b[=3]'}", "a1#{2}b[=3]"); + +assertOutput("<@r'${1} #{1} [=1]'?interpret />", "1 #{1} [=1]"); +assertOutput("${'\"${1} #{1} [=1]\"'?eval}", "1 #{1} [=1]"); } @Test @@ -41,10 +55,22 @@ public class InterpolationSyntaxTest extends TemplateTest { assertOutput("[= 1 ][= <#-- c --> 2 <#-- c --> ]", "12"); assertOutput("[ =1]", "[ =1]"); +// Legacy tag closing glitch is not emulated with this: assertErrorContains("<#if [true][0]]>", "\"]\"", "nothing open"); + +getConfiguration().setTagSyntax(SQUARE_BRACKET_TAG_SYNTAX); +assertOutput("[#if [true][0]]>[/#if]", ">"); +assertOutput("[=1][=2]${3}", "12${3}"); +getConfiguration().setTagSyntax(ANGLE_BRACKET_TAG_SYNTAX); assertOutput("[#ftl][#if [true][0]]>[/#if]", ">"); +assertOutput("[#ftl][=1][=2]${3}", "12${3}"); assertOutput("[='a[=1]b']", "a1b"); +assertOutput("[='a${1}#{2}b']", "a${1}#{2}b"); +assertOutput("[='a${1}#{2}b[=3]']", "a${1}#{2}b3"); + +assertOutput("<@r'${1} #{1} [=1]'?interpret />", "${1} #{1} 1"); +assertOutput("[='\"${1} #{1} [=1]\"'?eval]", "${1} #{1} 1"); } @Test @@ -53,6 +79,7 @@ public class InterpolationSyntaxTest extends TemplateTest { for (int syntax : new int[] { LEGACY_INTERPOLATION_SYNTAX, DOLLAR_INTERPOLATION_SYNTAX, SQUARE_BRACKET_INTERPOLATION_SYNTAX }) { assertOutput("[#if [true][0]]t[#else]f[/#if]", "t"); +assertOutput("[@r'[#if [true][0]]t[#else]f[/#if]'?interpret /]", "t"); } } @@ -65,7 +92,7 @@ public class InterpolationSyntaxTest extends TemplateTest { assertOutput(ftl, "t"); } -// Glitch is not emulated with this: +// Legacy tag closing glitch is not emulated with this: getConfiguration().setInterpolationSyntax(SQUARE_BRACKET_INTERPOLATION_SYNTAX); assertErrorContains(ftl, "\"]\""); }
[04/12] incubator-freemarker git commit: Manual: Noting some common pitfalls when using extended Java decimal format
Manual: Noting some common pitfalls when using extended Java decimal format Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/c630a41a Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/c630a41a Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/c630a41a Branch: refs/heads/2.3 Commit: c630a41ab68059ba2e658aaea4281cd512b2f38e Parents: 54bd25b Author: ddekanyAuthored: Tue Mar 13 09:48:39 2018 +0100 Committer: ddekany Committed: Tue Mar 13 09:48:39 2018 +0100 -- src/manual/en_US/book.xml | 15 +++ 1 file changed, 15 insertions(+) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/c630a41a/src/manual/en_US/book.xml -- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index 231b607..52f67af 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -15568,6 +15568,13 @@ German people write: 12.345.678,00 extended Java decimal format + + You need at least FreeMarker 2.3.24 for these to work. + Before that, extended Java decimal format parts are just + silently ignored by + java.text.DecimalFormat. + + FreeMarker extends the Java decimal format patterns with extra options. These options are name-value pairs, specified after two semicolons (;;) at the end of the format @@ -15581,6 +15588,14 @@ Extended decimal format: ${10002.5?string[",000;; roundingMode=halfUp Standard decimal format: 10,002 Extended decimal format: 10_003 + + A very easy mistake to make is just using a single + semicolon instead of two. It won't even result in an error, as + java.text.DecimalFormat thinks you have just + specified some weird format for negative numbers. So remember to + use two semicolons. + + Above, in the extended decimal format, we have specified half-up rounding mode and group separator "_". The table of all options follows (note that these are defined by
incubator-freemarker git commit: Cleaned up more lexer/parser logic related to the handling of tag-closer delimiters ('>' and ']'). This has yielded the following two change log entries (and some impr
Repository: incubator-freemarker Updated Branches: refs/heads/2.3-gae f55f9d891 -> 01294537b Cleaned up more lexer/parser logic related to the handling of tag-closer delimiters ('>' and ']'). This has yielded the following two change log entries (and some improvements in error message quality, but that's hardly noticeable): 1. When the incompatible_improvements setting is set to 2.3.28 (or greater), fixed legacy parser glitch where a tag can be closed with an illegal ] (when it's not part of an expression) despite that the tag syntax is set to angle brackets. For example <#if x] worked just like <#if x>. Note that it doesn't affect the legal usage of ], like <#if x[0]> works correctly without this fix as well. 2. Fixed parser bug that disallowed using > at the top-level inside an interpolation (${...}). It had the same reason why <#if x > y> doesn't work as naively expected, but there's no real ambiguity in ${x > y}, so now it's allowed. Note that ${(x > y)?c} and ${(x > y)?string('y', 'n')}, which are how booleans are commonly printed, have always worked, as the > operation is not on the top-level inside the interpolation. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/01294537 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/01294537 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/01294537 Branch: refs/heads/2.3-gae Commit: 01294537b882d06e2ac7df5b5fff590bf45f5227 Parents: f55f9d8 Author: ddekanyAuthored: Mon Mar 19 22:19:37 2018 +0100 Committer: ddekany Committed: Mon Mar 19 22:19:37 2018 +0100 -- .../java/freemarker/template/Configuration.java | 4 + src/main/javacc/FTL.jj | 77 src/manual/en_US/book.xml | 27 +++ .../core/InterpolationSyntaxTest.java | 33 +++-- .../core/ParsingErrorMessagesTest.java | 66 ++--- .../templates/string-builtins3.ftl | 4 +- 6 files changed, 147 insertions(+), 64 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/01294537/src/main/java/freemarker/template/Configuration.java -- diff --git a/src/main/java/freemarker/template/Configuration.java b/src/main/java/freemarker/template/Configuration.java index 3114747..5376dda 100644 --- a/src/main/java/freemarker/template/Configuration.java +++ b/src/main/java/freemarker/template/Configuration.java @@ -885,6 +885,10 @@ public class Configuration extends Configurable implements Cloneable, ParserConf * (Of course, the parameter default value expression is still evaluated in the context of the called * macro or function.) Similarly, {@code .macro_caller_template_name} (which itself was added in 2.3.28), * when used in a macro call argument, won't be incorrectly evaluated in the context of the called macro. + * Fixed legacy parser glitch where a tag can be closed with an illegal {@code ]} (when it's not part + * of an expression) despite that the tag syntax is set to angle brackets. For example {@code <#if x]} + * worked just like {@code <#if x>}. Note that it doesn't affect the legal usage of {@code ]}, like + * {@code <#if x[0]>} works correctly without this fix as well. * * * http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/01294537/src/main/javacc/FTL.jj -- diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj index 26f3368..630ef39 100644 --- a/src/main/javacc/FTL.jj +++ b/src/main/javacc/FTL.jj @@ -667,7 +667,7 @@ TOKEN_MGR_DECLS: if (!strictSyntaxMode) { // Legacy feature (or bug?): Tag syntax never gets estabilished in non-strict mode. -// We do establilish the naming convention though. +// We do establish the naming convention though. checkNamingConvention(tok, tokenNamingConvention); SwitchTo(newLexState); return; @@ -684,6 +684,24 @@ TOKEN_MGR_DECLS: // We only get here if this is a strict FTL tag. directiveSyntaxEstablished = true; +if (incompatibleImprovements >= _TemplateAPI.VERSION_INT_2_3_28 +|| interpolationSyntax == SQUARE_BRACKET_INTERPOLATION_SYNTAX) { + // For END_xxx tags, as they can't contain expressions, the whole tag is a single token. So this is the only + // chance to check if we got something inconsistent like `') { + if