You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Hussachai Puripunpinyo (Jira)" <ji...@apache.org> on 2021/06/04 00:31:00 UTC

[jira] [Commented] (JEXL-336) Escape some control characters

    [ https://issues.apache.org/jira/browse/JEXL-336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17356985#comment-17356985 ] 

Hussachai Puripunpinyo commented on JEXL-336:
---------------------------------------------

I'm not using JXLT and didn't know that it's broken. Sorry and thank you :)

> Escape some control characters
> ------------------------------
>
>                 Key: JEXL-336
>                 URL: https://issues.apache.org/jira/browse/JEXL-336
>             Project: Commons JEXL
>          Issue Type: Bug
>            Reporter: Hussachai Puripunpinyo
>            Assignee: Henri Biestro
>            Priority: Major
>             Fix For: 3.2
>
>
> I found that JEXL doesn't honor the escape control characters such as \n, \t. 
> To reproduce this is simply evaluate this string "a\t\b" and it will yield "a\t\b" instead of "a   b".
> The test code can explain this better. Note that I have to escape twice because one is for Java and another one is for JEXL.
> {code:java}
> String[][] strings = new String[][] {
>     new String[] {"a\nb\tc", "'a\nb\tc'"}, // we still honor the actual characters
>     new String[] {"a\nb\tc", "'a\\nb\\tc'"},
>     new String[] {"a\nb\tc", "\"a\\nb\\tc\""},
>     new String[] {"\b\t\n\f\r", "'\\b\\t\\n\\f\\r'"},
>     new String[] {"'hi'", "'\\'hi\\''"},
>     new String[] {"\"hi\"", "'\"hi\"'"},
>     new String[] {"\"hi\"", "'\"hi\"'"},
> };
> for(String[] pair: strings) {
>     String output = StringParser.buildString(pair[1], true);
>     Assert.assertEquals(pair[0], output);
> }{code}
> This change doesn't cover all control characters because it won't be used. I follow the [ES5 JavaScript spec|http://es5.github.io/x7.html#x7.8.4] for the control characters that it supports except \v which Java itself doesn't support. I don't think it's being used that much anyway. Supporting \v is tricky. We can represent it with the unicode value (\u000B) but JEXL is Java and doing that in Java is not possible. Developers have to put the unicode in the String anyway when it's used in the host language. That's why \v is not included in the list. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)