You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Stepan Koltsov (JIRA)" <de...@velocity.apache.org> on 2007/02/24 00:38:05 UTC

[jira] Created: (VELOCITY-519) Java escape sequences should work in Velocity macros

Java escape sequences should work in Velocity macros
----------------------------------------------------

                 Key: VELOCITY-519
                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
             Project: Velocity
          Issue Type: New Feature
    Affects Versions: 1.5 beta2
            Reporter: Stepan Koltsov


Following test should work:

===
    public void testJavaEscape() throws Exception {
        VelocityEngine ve = new VelocityEngine();
        ve.init();
        Context context = new VelocityContext();

        StringWriter writer = new StringWriter();
        ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
        assertEquals("a", writer.toString());

        writer = new StringWriter();
        ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
        assertEquals("\n", writer.toString());
    }
===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Stepan Koltsov (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475557 ] 

Stepan Koltsov commented on VELOCITY-519:
-----------------------------------------

Nathan, EscapeTool does escaping. I need something opposite.

I need ability to insert any Unicode character in template. Any programming language, templating language or markup language allows this. Velocity shoud too.

Inserting concrete characters is not unescaping.

My templates are stored in encoding that is not Unicode. So it is not possible to insert some characters I have to insert (some unicode characters, like em dash). In Java I can write: \u2014, in HTML: &#x2014;. I want to have something similar in Velocity.

I think it is bad idea to have special tool to generate characters.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Will Glass-Husain (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475592 ] 

Will Glass-Husain commented on VELOCITY-519:
--------------------------------------------

Been thinking-- is this backwards compatible?  I'm not sure.

Mostly, it is.  But if a user is generating Java code and expects the escape sequences to pass through, then we're in trouble.

Any thoughts?

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Updated: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Stepan Koltsov (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stepan Koltsov updated VELOCITY-519:
------------------------------------

    Attachment: velocity-unescape-only-u-2007-02-24-stepancheg.diff

Another patch, that enables only \u escapes, in backward compatible way :)

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Will Glass-Husain (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475618 ] 

Will Glass-Husain commented on VELOCITY-519:
--------------------------------------------

That's a good point.  If the \u00b1 format didn't work at all before, there's no harm in adding it in.  And it adds new capability.  (inserting characters into the body that you might not have been able to before).

But if \t, \r, \n were were just passed through (and possibly this was desired by someone generating Java code) we shouldn't intercept it.  So I withdraw my suggestion for \t, \r, \n parsing.  

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Reopened: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Will Glass-Husain (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Will Glass-Husain reopened VELOCITY-519:
----------------------------------------


I don't see this something worth spending time on myself, but I think I'd accept a patch to add this in.  

It's a pretty basic functionality, and a fairly isolated change to the java cc tokenizing code.  I'd want to see something comprehensive (e.g. supporting \n \r as well as unicode) before committing.

It would help Stepan if you could give some use cases describing why this is needed and what problems it would solve.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Christopher Schultz (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475718 ] 

Christopher Schultz commented on VELOCITY-519:
----------------------------------------------

If \uXXXX syntax works, then it's still possible to insert newlines (\u000a and \u000c) and tabs (\u0009), even if the escape sequences aren't as recognizable.

Another option would be to fix bug VELOCITY-520 such that \uXXXX escapes do not cause an error any longer, and then create a macro that takes a string and converts \u and \r, \n, \t, etc. escape sequences into their actual characters.


> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>             Fix For: 1.6
>
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Resolved: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Bubna resolved VELOCITY-519.
-----------------------------------

       Resolution: Later
    Fix Version/s:     (was: 1.6)
                   2.0

Since VELOCITY-520 is fixed using the backwards compatible unicode-escape only patch, i'm going to resolve this as LATER.  We can revisit debate about other Java escape sequences when we work on version 2.0.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>          Components: Engine
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>             Fix For: 2.0
>
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Stepan Koltsov (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475572 ] 

Stepan Koltsov commented on VELOCITY-519:
-----------------------------------------

Christopher,

It is not easy to work with some UTF-8 characters in Velocity template. For example, it is hard to maintain code with em dash in text editor with fixed width font. With some unicode characters, like non-breakable space, it is not possible to work in the most text editors.

BTW, you are not right, that java mandates ISO-8859-1:

[yozh@PowerBook:...ft/velocity/engine-trunk]% javac -help |& grep encoding                                       
  -encoding <encoding>       Specify character encoding used by source files

Another reason for unicode escapes is that my company mandates that all source files must be in windows-1251.

I personally don't need \r or \n escapes, but I think they should be enabled in version 2.0.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Updated: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Henning Schmiedehausen (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henning Schmiedehausen updated VELOCITY-519:
--------------------------------------------

    Component/s: Engine

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>          Components: Engine
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>             Fix For: 1.6
>
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Christopher Schultz (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475562 ] 

Christopher Schultz commented on VELOCITY-519:
----------------------------------------------

Stepan,
The only reason that Java needs unicode escaping in source files is because java source files are defined to be ISO-8859-1. You simply cannot put higher characters like Kanji into a Java source file, hence the \u1234 escape sequences. Same thing with properties files.

Velocity template files have no such restrictions IIRC. Why not simply use UTF-8 encoding and put your special characters directly into your template files? There's really no need for escaping of these kinds of things.

Now, newline escaping is another story, unless there is a non '\n' (or '\r') newline character that I don't know about.


> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Updated: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Stepan Koltsov (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stepan Koltsov updated VELOCITY-519:
------------------------------------

    Attachment: velocity-unescape-2007-02-24-stepancheg.diff

Trivial patch, not backward compatible.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475554 ] 

Nathan Bubna commented on VELOCITY-519:
---------------------------------------

I don't see how this could be done in a backwards compatible way.  I don't want to be pigheaded about this, but i really think this doesn't belong in a 1.x version.  Of course, there's no reason someone can't start working on 2.0 now...

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475897 ] 

Nathan Bubna commented on VELOCITY-519:
---------------------------------------

The only consensus here is that we should fix the lexer error when \uXXXX appears in a string definition.  This would be Stepan's second attached patch.

And yes, this will allow you to insert tabs, carriage returns and line feeds by typing *six* characters for each instead of just typing the one tab, CR or LF character.   why do:
#set( $tab = "\u0009" ) 
which doesn't even work yet, when
#set( $tab = "	" )
already works?

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>             Fix For: 1.6
>
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Christoph Reck (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475835 ] 

Christoph Reck commented on VELOCITY-519:
-----------------------------------------

If inserting & automatic translation of unicode characters work, the template writer might predefine and use $tab, $CR, $LF constants instead of \t, \r \n thus keeping BC.

#set( $tab = "\u0009" )
...
#if( $samplestring.contains($tab) ) 

P.S. in the past I used the UrlDecoder to achieve this.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>             Fix For: 1.6
>
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475585 ] 

Nathan Bubna commented on VELOCITY-519:
---------------------------------------

Thanks, i'll let Will take responsibility for the unicode escapes patch if he's willing.  If not, i guess i'd be willing to do it since it's better than the current bug. :)

As for the line breaks, i don't see why anyone should need them when the can just put the actual carriage return or new line right into the string.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Resolved: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Bubna resolved VELOCITY-519.
-----------------------------------

    Resolution: Won't Fix

Sorry Stepan, VTL (Velocity Template Language) is *not* java, nor do we have any intention of making it so.   It is designed to be a simple templating language with a small feature set that is quick for anyone to learn.  We have several times in the past debated supporting various escaping schemes in string literal definitions (that's what your example is about, not macros), but the only escaping feature that managed to gather a consensus among the developers was MySQL like quote and double quote escaping and even that has not been added yet.  Search the archives for more history on this.

Do your escaping in Java or create a tool (or even a patch for this: http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/EscapeTool.html) to support doing this within templates.

Personally, the soonest i would be interested in re-opening discussion on escaping within string definitions would be when work has started on Velocity 2.0.  Until then, this gets a -1 from me.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Will Glass-Husain (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12486531 ] 

Will Glass-Husain commented on VELOCITY-519:
--------------------------------------------

Nice work, Nathan (and kudos to Stepan)  on VELOCITY-520.

I seem to be the only one on this thread who liked the idea of \t, \r, \n.   But after thinking about it, I'm worried about compatibility of templates that specify those symbols when generating Java code, so I withdraw my suggestion.

(or at least, I agree we should not do this for any 1.x releases).

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>          Components: Engine
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>             Fix For: 2.0
>
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Updated: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Will Glass-Husain (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Will Glass-Husain updated VELOCITY-519:
---------------------------------------

    Fix Version/s: 1.6

assigning to 1.6 since there's consensus we should do something here.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>             Fix For: 1.6
>
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475613 ] 

Nathan Bubna commented on VELOCITY-519:
---------------------------------------

No, it's not backwards compatible.  The unicode escapes are merely by virtue of the fact that they caused an error previously.  \n \r and \t are not backwards compatible.  And if you want to insert one of those characters, just insert them in the string.  There's no need to enter it in escaped form and then make Velocity convert for you when you can just put the character in the string yourself.  No tools or patches necessary here, and definitely no need to break backwards compatibility.

> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-519) Java escape sequences should work in Velocity macros

Posted by "Will Glass-Husain (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475589 ] 

Will Glass-Husain commented on VELOCITY-519:
--------------------------------------------

Stepan makes good points (I believe) about the utility of including escaped unicode characters.  Actually, I face similar issues from time to time.  My main text editor doesn't do a good job with UTF-8.

I advocate \n, \r, and more importantly, \t for comprehensiveness.  If we allow unicode escaping then users will expect the other items.   Are there more that need to be included?

I can imagine cases where inserting a tab character might be useful.  For example, you might want to compare a string to \t in an #if statement.  The following

#if($samplestring.contains("\t"))

is more readable than

#if($samplestring.contains("\t"))

You could do this with a tool, but this is simpler syntax.

WILL


> Java escape sequences should work in Velocity macros
> ----------------------------------------------------
>
>                 Key: VELOCITY-519
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-519
>             Project: Velocity
>          Issue Type: New Feature
>    Affects Versions: 1.5 beta2
>            Reporter: Stepan Koltsov
>         Attachments: velocity-unescape-2007-02-24-stepancheg.diff, velocity-unescape-only-u-2007-02-24-stepancheg.diff
>
>
> Following test should work:
> ===
>     public void testJavaEscape() throws Exception {
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         Context context = new VelocityContext();
>         StringWriter writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\u0061\")$v");
>         assertEquals("a", writer.toString());
>         writer = new StringWriter();
>         ve.evaluate(context, writer, "test","#set($v = \"\\n\")$v");
>         assertEquals("\n", writer.toString());
>     }
> ===

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org