[jira] [Comment Edited] (JEXL-302) JexlScript.getVariables returns strange values for array access
[ https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17034586#comment-17034586 ] Henri Biestro edited comment on JEXL-302 at 2/11/20 4:39 PM: - That subject is moot if you use a JexBuilder(). collectAll(false) as in: {code:java} JexlEngine jexld = new JexlBuilder().collectAll(false).create(); e = jexld.createScript("x.y[{'z': 't'}]"); vars = e.getVariables(); Assert.assertEquals(1, vars.size()); Assert.assertTrue(eq(mkref(new String[][]{{"x", "y"}}), vars));} {code} In the collectAll(true) case, the logic is in the actual intent of getVariables ; statically capture the elements that will potentially influence the script execution flow, ie all variables. Since one can configure JEXL so that a.b is equivalent to a['b'], it stands to reason that a a[['b', 'c’]] can be interpreted as [a.b, a.c]. , thus the a, ['b', 'c'] resulting of getVariables. The same logic can be applied to constant sets and maps. For instance: {code:java} script = JEXL.createScript("moon.landing[['', 'MM', 'dd']]"); result = (List) script.execute(ctxt); Assert.assertEquals(Arrays.asList("1969", "7", "20"), result); {code} In this example, the script {code:java} moon.landing[['', 'MM', 'dd']]{code} is equivalent to {code:java} [ moon.landing., moon.landing.MM, moon.landing.dd ] {code} With a bit of added parsing, it becomes possible to determine those from getVariables. I'm adding a test case to illustrate, [JEXL-302: added a test for JexBuilder.captureAll() and JexlScript.get…|https://github.com/apache/commons-jexl/commit/09db242b8cffbf63ad4a59d4e62f3ac358d4be24] was (Author: henrib): That subject is moot if you use a JexBuilder().captureAll(false) as in: {code:java} JexlEngine jexld = new JexlBuilder().collectAll(false).create(); e = jexld.createScript("x.y[{'z': 't'}]"); vars = e.getVariables(); Assert.assertEquals(1, vars.size()); Assert.assertTrue(eq(mkref(new String[][]{{"x", "y"}}), vars));} {code} In the captureAll(true) case, the logic is in the actual intent of getVariables ; statically capture the elements that will potentially influence the script execution flow, ie all variables. Since one can configure JEXL so that a.b is equivalent to a['b'], it stands to reason that a a[['b', 'c’]] can be interpreted as [a.b, a.c]. , thus the a, ['b', 'c'] resulting of getVariables. The same logic can be applied to constant sets and maps. For instance: {code:java} script = JEXL.createScript("moon.landing[['', 'MM', 'dd']]"); result = (List) script.execute(ctxt); Assert.assertEquals(Arrays.asList("1969", "7", "20"), result); {code} In this example, the script {code:java} moon.landing[['', 'MM', 'dd']]{code} is equivalent to {code:java} [ moon.landing., moon.landing.MM, moon.landing.dd ] {code} With a bit of added parsing, it becomes possible to determine those from getVariables. I'm adding a test case to illustrate, [JEXL-302: added a test for JexBuilder.captureAll() and JexlScript.get…|https://github.com/apache/commons-jexl/commit/09db242b8cffbf63ad4a59d4e62f3ac358d4be24] > JexlScript.getVariables returns strange values for array access > --- > > Key: JEXL-302 > URL: https://issues.apache.org/jira/browse/JEXL-302 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Minor > Fix For: 3.2 > > > I can not understand the logic behind the current implementation of > {{JexlScript.getVariables()}} method. From the documentation we know that the > result should be the set of script variables. For the code > {code:java} > a[b][c]{code} > it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code > {code:java} > a[b]['c']{code} > it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} > and {{c}}. The documentation states that variables with multiple fragments > are ant-ish variables, but I don't have any of ant-ish variables in the > example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} > and {{b}} as a result. -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Comment Edited] (JEXL-302) JexlScript.getVariables returns strange values for array access
[ https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16854569#comment-16854569 ] Dmitri Blinov edited comment on JEXL-302 at 6/4/19 12:49 PM: - I have got your point, but for the sake of argument, as of now - {{a.b}} is not equivalent to {{a["b"]}}. First because of ant-ish variables. One can only address anti-sh variable as {{a.b}}, not as {{a["b"]}}. Strictly speaking {{a["b"]}} is not equivalent to {{a.b}}, because we can have {{a["b+c"]}}, but we can not have {{a.(b+c)}}. And second - because we can have {{propertyGet()/propertySet()}} and {{arrayGet()/arraySet()}} to be overloaded separately, so that they can perform different operations. I also understand that what the {{a.b}} is resolved into (whether this a variable {{a.b}} or only {{a}} is a variable, and {{b}} is property name) is decided during runtime, so this can not be defined from syntax representation tree alone - a tough task for {{JexlScript.getVariables()}}. Still, the example of issue {code:java} a[b]['c']{code} does not follow the pattern of {{a.b}} == {{a["b"]}}. From what I get from the {{JexlScript.getVariables(),}} the code {{a[b]['c']}} is equivalent to {{a[b.c]}}, which in fact should be equivalent to {{a[b["c"]]}}. Something is wrong here... was (Author: dmitri_blinov): I have got your point, but for the sake of argument, as of now - {{a.b}} is not equivalent to {{a["b"]}}. First because of ant-ish variables. One can only address anti-sh variable as {{a.b}}, not as {{a["b"]}}. And second - because we can have {{propertyGet()/propertySet()}} and {{arrayGet()/arraySet()}} to be overloaded separately. I understand that what {{a.b}} is resolved into (whether this a variable {{a.b}} or only {{a}} is a variable, and {{b}} is property name) is decided during runtime, so this can not be defined from syntax representation tree - a tough task for {{JexlScript.getVariables()}}. Still, the example of issue {code:java} a[b]['c']{code} does not follow the pattern in question. From your explanation, and from what I get from the {{JexlScript.getVariables(),}} the code {{a[b]['c']}} is equivalent to {{a[b.c]}}, which in fact should be equivalent to {{a[b["c"]]}}. Something is wrong here... > JexlScript.getVariables returns strange values for array access > --- > > Key: JEXL-302 > URL: https://issues.apache.org/jira/browse/JEXL-302 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Minor > Fix For: 3.2 > > > I can not understand the logic behind the current implementation of > {{JexlScript.getVariables()}} method. From the documentation we know that the > result should be the set of script variables. For the code > {code:java} > a[b][c]{code} > it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code > {code:java} > a[b]['c']{code} > it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} > and {{c}}. The documentation states that variables with multiple fragments > are ant-ish variables, but I don't have any of ant-ish variables in the > example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} > and {{b}} as a result. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Comment Edited] (JEXL-302) JexlScript.getVariables returns strange values for array access
[ https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16845983#comment-16845983 ] Henri Biestro edited comment on JEXL-302 at 5/22/19 3:28 PM: - I suspect your (failing) example is: why does {{a['b'][c]}} generate {{["a",”b"]}} and {{["c"]}} as the variable set of lists ? This probably stems from the current behaviour where {{a.b]}} is equivalent to {{a["b"]}} or {{a.0}} is equivalent to {{a[0]}}. There are plenty of tests in VarTests.testRef(...) that indicate the intent for getVariable to collect that equivalence. It is guaranteed that the 1st member of each segment (list) is the name of a variable; one can consider the whole segment as the actual varying element ( as in a.b value changes with a and a.b ). Does this make more sense? was (Author: henrib): I suspect your (failing) example is: why does {{a['b'][c]}} generate {{["a",”b"]}} and {{["c"]}} as the variable set of lists ? This probably stems from the current behaviour where {{[a.b]]}} is equivalent to {{a["b"]}} or {{a.0}} is equivalent to {{a[0]}}. There are plenty of tests in VarTests.testRef(...) that indicate the intent for getVariable to collect that equivalence. It is guaranteed that the 1st member of each segment (list) is the name of a variable; one can consider the whole segment as the actual varying element ( as in a.b value changes with a and a.b ). Does this make more sense? > JexlScript.getVariables returns strange values for array access > --- > > Key: JEXL-302 > URL: https://issues.apache.org/jira/browse/JEXL-302 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Priority: Minor > > I can not understand the logic behind the current implementation of > {{JexlScript.getVariables()}} method. From the documentation we know that the > result should be the set of script variables. For the code > {code:java} > a[b][c]{code} > it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code > {code:java} > a[b]['c']{code} > it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} > and {{c}}. The documentation states that variables with multiple fragments > are ant-ish variables, but I don't have any of ant-ish variables in the > example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} > and {{b}} as a result. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Comment Edited] (JEXL-302) JexlScript.getVariables returns strange values for array access
[ https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16845983#comment-16845983 ] Henri Biestro edited comment on JEXL-302 at 5/22/19 3:28 PM: - I suspect your (failing) example is: why does {{a['b'][c]}} generate {{["a",”b"]}} and {{["c"]}} as the variable set of lists ? This probably stems from the current behaviour where {{a.b}} is equivalent to {{a["b"]}} or {{a.0}} is equivalent to {{a[0]}}. There are plenty of tests in VarTests.testRef(...) that indicate the intent for getVariable to collect that equivalence. It is guaranteed that the 1st member of each segment (list) is the name of a variable; one can consider the whole segment as the actual varying element ( as in a.b value changes with a and a.b ). Does this make more sense? was (Author: henrib): I suspect your (failing) example is: why does {{a['b'][c]}} generate {{["a",”b"]}} and {{["c"]}} as the variable set of lists ? This probably stems from the current behaviour where {{a.b]}} is equivalent to {{a["b"]}} or {{a.0}} is equivalent to {{a[0]}}. There are plenty of tests in VarTests.testRef(...) that indicate the intent for getVariable to collect that equivalence. It is guaranteed that the 1st member of each segment (list) is the name of a variable; one can consider the whole segment as the actual varying element ( as in a.b value changes with a and a.b ). Does this make more sense? > JexlScript.getVariables returns strange values for array access > --- > > Key: JEXL-302 > URL: https://issues.apache.org/jira/browse/JEXL-302 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Priority: Minor > > I can not understand the logic behind the current implementation of > {{JexlScript.getVariables()}} method. From the documentation we know that the > result should be the set of script variables. For the code > {code:java} > a[b][c]{code} > it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code > {code:java} > a[b]['c']{code} > it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} > and {{c}}. The documentation states that variables with multiple fragments > are ant-ish variables, but I don't have any of ant-ish variables in the > example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} > and {{b}} as a result. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Comment Edited] (JEXL-302) JexlScript.getVariables returns strange values for array access
[ https://issues.apache.org/jira/browse/JEXL-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16845983#comment-16845983 ] Henri Biestro edited comment on JEXL-302 at 5/22/19 3:27 PM: - I suspect your (failing) example is: why does {{a['b'][c]}} generate {{["a",”b"]}} and {{["c"]}} as the variable set of lists ? This probably stems from the current behaviour where {{[a.b]]}} is equivalent to {{a["b"]}} or {{a.0}} is equivalent to {{a[0]}}. There are plenty of tests in VarTests.testRef(...) that indicate the intent for getVariable to collect that equivalence. It is guaranteed that the 1st member of each segment (list) is the name of a variable; one can consider the whole segment as the actual varying element ( as in a.b value changes with a and a.b ). Does this make more sense? was (Author: henrib): I suspect your (failing) example is: why does {{a['b'][c]}} generate {{["a",”b"]}} and {{["c"]}} as the variable set of lists ? This probably stems from the current behaviour where {[a.b]] is equivalent to{{a["b"]}} or {{a.0}} is equivalent to {{a[0]}}. There are plenty of tests in VarTests.testRef(...) that indicate the intent for getVariable to collect that equivalence. It is guaranteed that the 1st member of each segment (list) is the name of a variable; one can consider the whole segment as the actual varying element ( as in a.b value changes with a and a.b ). Does this make more sense? > JexlScript.getVariables returns strange values for array access > --- > > Key: JEXL-302 > URL: https://issues.apache.org/jira/browse/JEXL-302 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Priority: Minor > > I can not understand the logic behind the current implementation of > {{JexlScript.getVariables()}} method. From the documentation we know that the > result should be the set of script variables. For the code > {code:java} > a[b][c]{code} > it gives three variables {{a}}, {{b}}, {{c}}. So far so good. But for the code > {code:java} > a[b]['c']{code} > it returns {{a}} and {{b c}}, where second variable has two fragments {{b}} > and {{c}}. The documentation states that variables with multiple fragments > are ant-ish variables, but I don't have any of ant-ish variables in the > example, and {{'c'}} is not a variable, but a constant. I expect to get {{a}} > and {{b}} as a result. -- This message was sent by Atlassian JIRA (v7.6.3#76005)