commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Blinov (Jira)" <j...@apache.org>
Subject [jira] [Commented] (JEXL-307) Variable redeclaration option
Date Fri, 01 Nov 2019 13:35:00 GMT

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

Dmitri Blinov commented on JEXL-307:
------------------------------------

The following test throws NPE
{code:java}
    @Test
    public void testLexical() throws Exception {
        JexlEngine Jexl = new JexlBuilder().silent(false).strict(true).lexical(true).create();
        JxltEngine Jxlt = Jexl.createJxltEngine();
        JexlEvalContext ctxt = new JexlEvalContext(new MapContext());
        JexlOptions options = ctxt.getEngineOptions();
        // ensure errors will throw
        options.setLexical(true);
        String rpt
                = "<report>\n"
                + "\n$$var y = 1; var x = 2;"
                + "\n${x + y}"
                + "\n</report>\n";
        JxltEngine.Template t = Jxlt.createTemplate("$$", new StringReader(rpt));
        StringWriter strw = new StringWriter();
        t.evaluate(ctxt, strw);
        String output = strw.toString();
        String ctl = "<report>\n\n3\n</report>\n";
        Assert.assertEquals(ctl, output);
    }
{code}
 

> Variable redeclaration option
> -----------------------------
>
>                 Key: JEXL-307
>                 URL: https://issues.apache.org/jira/browse/JEXL-307
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.1
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>            Priority: Minor
>             Fix For: 3.2
>
>
> As of now, JEXL allows a script writer to redeclare a local variable during script evaluation.
> {code:java}
> var a = 1; var a = 2;{code}
> This may lead to potential errors with misspelled names and clashed variables. Checking
for already defined variable is a common feature of many languages. This feature can be implemented
in JEXL as an additional option of JexlFeatures class, enabled by default, thus allowing compatibility
with existing code.



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

Mime
View raw message