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 2021/02/06 20:28:18 UTC

[freemarker] branch 3 updated: Forward ported from 2.3-gae: Allowed escaping # with backlash in identifier names (not in string), as it used to occur in database column names.

This is an automated email from the ASF dual-hosted git repository.

ddekany pushed a commit to branch 3
in repository https://gitbox.apache.org/repos/asf/freemarker.git


The following commit(s) were added to refs/heads/3 by this push:
     new aed7d57  Forward ported from 2.3-gae: Allowed escaping # with backlash in identifier names (not in string), as it used to occur in database column names.
aed7d57 is described below

commit aed7d57de710a80725b3213e78bf185839c795ac
Author: ddekany <dd...@apache.org>
AuthorDate: Sat Feb 6 17:42:00 2021 +0100

    Forward ported from 2.3-gae: Allowed escaping # with backlash in identifier names (not in string), as it used to occur in database column names.
---
 .../org/apache/freemarker/core/cano-identifier-escaping.f3au        | 6 +++---
 .../org/apache/freemarker/core/cano-identifier-escaping.f3au.out    | 4 ++--
 .../freemarker/core/templatesuite/expected/identifier-escaping.txt  | 2 +-
 .../core/templatesuite/templates/identifier-escaping.f3ac           | 6 +++---
 .../java/org/apache/freemarker/core/util/TemplateLanguageUtils.java | 2 +-
 .../src/main/java/org/apache/freemarker/core/util/_StringUtils.java | 2 +-
 freemarker-core/src/main/javacc/FTL.jj                              | 3 ++-
 7 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-identifier-escaping.f3au b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-identifier-escaping.f3au
index c866a06..d484b4f 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-identifier-escaping.f3au
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-identifier-escaping.f3au
@@ -30,9 +30,9 @@
 </#function>
 ${f\-a("f-a")}
 
-<#assign \-\-\-\.\: = 'dash-dash-dash etc.'>
-${\-\-\-\.\:}
-${.vars['---.:']}
+<#assign \-\-\-\.\:\# = 'dash-dash-dash etc.'>
+${\-\-\-\.\:\#}
+${.vars['---.:#']}
 <#assign hash = { '--moz-prop': 'propVal' }>
 ${hash.\-\-moz\-prop}
 ${hash['--moz-prop']}
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-identifier-escaping.f3au.out b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-identifier-escaping.f3au.out
index f50dedb..ea66644 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-identifier-escaping.f3au.out
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-identifier-escaping.f3au.out
@@ -21,8 +21,8 @@
 
 <#function f\-a(p\-a)><#return p\-a + " works"/></#function>${f\-a("f-a")}
 
-<#assign \-\-\-\.\: = "dash-dash-dash etc.">${\-\-\-\.\:}
-${.vars["---.:"]}
+<#assign \-\-\-\.\:\# = "dash-dash-dash etc.">${\-\-\-\.\:\#}
+${.vars["---.:#"]}
 <#assign hash = {"--moz-prop": "propVal"}>${hash.\-\-moz\-prop}
 ${hash["--moz-prop"]}
 
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/expected/identifier-escaping.txt b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/expected/identifier-escaping.txt
index 6f7ba21..6783042 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/expected/identifier-escaping.txt
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/expected/identifier-escaping.txt
@@ -40,7 +40,7 @@ as5
 
 <catchAll x=1 y=2 z=3 data-foo=4 a:b.c=5 />
 
----.: = dash-dash-dash etc.
+---.:# = dash-dash-dash etc.
 @as@_a = as1
 as/b = as3
 as'c = as4
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/identifier-escaping.f3ac b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/identifier-escaping.f3ac
index 1d472a7..34f8c88 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/identifier-escaping.f3ac
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/identifier-escaping.f3ac
@@ -30,9 +30,9 @@
 </#function>
 ${f\-a("f-a")}
 
-<#assign \-\-\-\.\: = 'dash-dash-dash etc.'>
-${\-\-\-\.\:}
-${.vars['---.:']}
+<#assign \-\-\-\.\:\# = 'dash-dash-dash etc.'>
+${\-\-\-\.\:\#}
+${.vars['---.:#']}
 <#assign hash = { '--moz-prop': 'propVal' }>
 ${hash.\-\-moz\-prop}
 ${hash['--moz-prop']}
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/util/TemplateLanguageUtils.java b/freemarker-core/src/main/java/org/apache/freemarker/core/util/TemplateLanguageUtils.java
index fcc9db4..8548cfa 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/util/TemplateLanguageUtils.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/util/TemplateLanguageUtils.java
@@ -642,7 +642,7 @@ public final class TemplateLanguageUtils {
      * backslash. Currently it return {@code true} for these: {@code '-'}, {@code '.'} and {@code ':'}.
      */
     public static boolean isEscapedIdentifierCharacter(final char c) {
-        return c == '-' || c == '.' || c == ':';
+        return c == '-' || c == '.' || c == ':' || c ==  '#';
     }
 
     /**
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtils.java b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtils.java
index 96f6960..587b20f 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtils.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtils.java
@@ -1565,7 +1565,7 @@ public class _StringUtils {
         scanForQuotationType: for (int i = 0; i < name.length(); i++) {
             final char c = name.charAt(i);
             if (!(i == 0 ? TemplateLanguageUtils.isNonEscapedIdentifierStart(c) : TemplateLanguageUtils.isNonEscapedIdentifierPart(c)) && c != '@') {
-                if ((quotationType == 0 || quotationType == '\\') && (c == '-' || c == '.' || c == ':')) {
+                if ((quotationType == 0 || quotationType == '\\') && TemplateLanguageUtils.isEscapedIdentifierCharacter (c)) {
                     quotationType = '\\';
                 } else {
                     quotationType = '"';
diff --git a/freemarker-core/src/main/javacc/FTL.jj b/freemarker-core/src/main/javacc/FTL.jj
index 8abd3e8..0ebf620 100644
--- a/freemarker-core/src/main/javacc/FTL.jj
+++ b/freemarker-core/src/main/javacc/FTL.jj
@@ -1276,7 +1276,8 @@ TOKEN:
         ]
     >
     |
-    <#ESCAPED_ID_CHAR: "\\" ("-" | "." | ":")>
+    // Keep this in sync with TemplateLanguageUtils.isEscapedIdentifierCharacter
+    <#ESCAPED_ID_CHAR: "\\" ("-" | "." | ":" | "#")>
     |
     <#ID_START_CHAR: <NON_ESCAPED_ID_START_CHAR>|<ESCAPED_ID_CHAR>>
     |