Bug 1249773

Summary: [GSS](6.4.z) CLI if/else is not handling special characters strings with parenthesis
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Spolti <fspolti>
Component: CLIAssignee: Tomas Hofman <thofman>
Status: CLOSED CURRENTRELEASE QA Contact: Petr Kremensky <pkremens>
Severity: unspecified Docs Contact:
Priority: high    
Version: 6.4.2CC: bbaranow, bmaxwell, brian.stansberry, istudens, jawilson, jbilek, jboss-set, lkonno, thofman, tibrahim
Target Milestone: CR1   
Target Release: EAP 6.4.6   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1235746    

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.