Bug 1249773 - [GSS](6.4.z) CLI if/else is not handling special characters strings with parenthesis
Summary: [GSS](6.4.z) CLI if/else is not handling special characters strings with pare...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: CLI
Version: 6.4.2
Hardware: Unspecified
OS: Unspecified
high
unspecified
Target Milestone: CR1
: EAP 6.4.6
Assignee: Tomas Hofman
QA Contact: Petr Kremensky
URL:
Whiteboard:
Depends On:
Blocks: 1235746
TreeView+ depends on / blocked
 
Reported: 2015-08-03 18:43 UTC by Spolti
Modified: 2019-09-12 08:43 UTC (History)
10 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker WFCORE-868 0 Major Resolved CLI if/else is not handling special characters strings with parenthesis 2016-11-28 10:37:32 UTC
Red Hat Knowledge Base (Solution) 2148961 0 None None None 2016-02-03 18:41:35 UTC
Red Hat Knowledge Base (Solution) 2429721 0 None None None 2016-08-11 17:30:01 UTC

Comment 1 Spolti 2015-08-03 18:46:34 UTC
Created attachment 1058869 [details]
modified cli jar

Description of problem:
When using CLI if-else scripting that uses a string that contains parenthesis it fails with the following message:

Failed to handle 'if (outcome == success && result.value != "a64180c0)e7187af86b435229de904104") of /system-property=test:read-resource': Unexpected operation at 49 in '(outcome == success && result.value != "a64180c0)e7187af86b435229de904104")'

Where the position 49 is the ")".

I think that this validation is done here:
https://github.com/wildfly/wildfly-core/blob/61be46a71fc9499705b0a744b55bcdffa8721f3a/cli/src/main/java/org/jboss/as/cli/handlers/ifelse/ExpressionParser.java#L120

I added some outputs in the CLI:

parsing: '(outcome == success && result.value != "a64180c0)e7187af86b435229de904104")'
parsing: 'outcome == success && result.value != "a64180c0'
Input: outcome == success && result.value != "a64180c0
parsed: (&& [(== [outcome, success]), (!= [result.value, "a64180c0])])

It stops exactly where ")" are.



Version-Release number of selected component (if applicable):
JBoss EAP 6.4.2.
CLI: jboss-as-cli-7.5.2.Final-redhat-2.jar


How reproducible:
Create s CLI script like the following:

if (outcome == success && result.value != "a64180c0)e7187af86b435229de904104") of /system-property=test:read-resource
/system-property=test:write-attribute(name=value,value="a64180c0)e7187af86b435229de904104")
end-if
if (outcome != success) of /system-property=test:read-resource
/system-property=test:add(value="a64180c0)e7187af86b435229de904104")
end-if

Steps to Reproduce:
1. Create a cli flie with the content above
2. Execute it: bin/jboss-cli.sh -c --file=test.cli

Actual results:
It fail with this message:
Failed to handle 'if (outcome == success && result.value != "a64180c0)e7187af86b435229de904104") of /system-property=test:read-resource': Unexpected operation at 49 in '(outcome == success && result.value != "a64180c0)e7187af86b435229de904104")'

Expected results:
The property being executed and no errors should happen when we have a parenthesis in the middle of the if-else condition


Additional info:
To try to solve it I created the following method:

    private boolean inputIsInsideQuotes(String input){

        int occurs = 0;

        for (int i = 0; i < input.length(); i++){
            //System.out.println("Searching for quotes");
            if (input.charAt(i) == '\"') {
                //System.out.println("quotes found at " + i);
                occurs++;
            }
       }

       if (occurs >= 1){
           return true;
       } else {
           return false;
       }
    }



And changed the parseOperand method to ignore everything that is inside quotes:

 protected Operand parseOperand() throws CommandLineException {

        skipWhitespaces();
        if(pos == input.length()) {
            return null;
        }

        //System.out.println("have quotes? " + InputIsInsideQuotes(input));

        if(input.charAt(pos) == '(') {
            if (inputIsInsideQuotes(input)){
                //do nothing
            } else {
                int depthCount = 0;
                int endIndex = pos;
...


After this I successfully executed the same CLI script

[standalone@localhost:9999 /] /system-property=test:read-resource
[fspolti@my-laptop main]$ bin/jboss-cli.sh -c --file=test.cli

[user@my-laptop main]$ /bin/jboss-cli.sh -c 
[standalone@localhost:9999 /] /system-property=test:read-resource
{
    "outcome" => "success",
    "result" => {"value" => "a64180c0)e7187af86b435229de904104"}
}
[standalone@localhost:9999 /]

adding more parenthesis:
[user@my-laptop main]$  bin/jboss-cli.sh -c --file=test.cli
Input: (outcome == success && result.value != "a64180c0)e7187af86b435229()()()(de904104")

[fspolti@my-laptop main]$  bin/jboss-cli.sh -c 
[standalone@localhost:9999 /] /system-property=lhs.gateway:read-resource
{
    "outcome" => "success",
    "result" => {"value" => "a64180c0)e7187af86b435229()()()(de904104"}
}




I attached the script and the modified jar.

Comment 3 Spolti 2015-08-03 18:48:16 UTC
Created attachment 1058871 [details]
modified jar

Comment 4 Tomas Hofman 2015-08-05 08:27:15 UTC
PR: https://github.com/jbossas/jboss-eap/pull/2515

Comment 5 Tomas Hofman 2015-08-07 12:10:21 UTC
Switching back to assigned before upstream is resolved.

Comment 11 Tomas Hofman 2015-09-03 14:36:09 UTC
Upstream rejected.

See discussion in upstream PR: https://github.com/wildfly/wildfly-core/pull/938

Comment 16 Tomas Hofman 2015-09-17 12:48:22 UTC
PR: https://github.com/jbossas/jboss-eap/pull/2558

Comment 18 Jiří Bílek 2016-01-20 09:19:08 UTC
Verified with EAP 6.4.6.CP.CR2.

Comment 19 Petr Penicka 2017-01-17 11:48:17 UTC
Retroactively bulk-closing issues from released EAP 6.4 cumulative patches.

Comment 20 Petr Penicka 2017-01-17 11:48:29 UTC
Retroactively bulk-closing issues from released EAP 6.4 cumulative patches.


Note You need to log in before you can comment on or make changes to this bug.