Bug 1249773 - [GSS](6.4.z) CLI if/else is not handling special characters strings with parenthesis
[GSS](6.4.z) CLI if/else is not handling special characters strings with pare...
Status: CLOSED CURRENTRELEASE
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: CLI (Show other bugs)
6.4.2
Unspecified Unspecified
high Severity unspecified
: CR1
: EAP 6.4.6
Assigned To: Tomas Hofman
Petr Kremensky
:
Depends On:
Blocks: 1235746
  Show dependency treegraph
 
Reported: 2015-08-03 14:43 EDT by Spolti
Modified: 2017-01-17 06:48 EST (History)
10 users (show)

See Also:
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: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
JBoss Issue Tracker WFCORE-868 Major Resolved CLI if/else is not handling special characters strings with parenthesis 2016-11-28 05:37 EST
Red Hat Knowledge Base (Solution) 2148961 None None None 2016-02-03 13:41 EST
Red Hat Knowledge Base (Solution) 2429721 None None None 2016-08-11 13:30 EDT

  None (edit)
Comment 1 Spolti 2015-08-03 14:46:34 EDT
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 14:48:16 EDT
Created attachment 1058871 [details]
modified jar
Comment 4 Tomas Hofman 2015-08-05 04:27:15 EDT
PR: https://github.com/jbossas/jboss-eap/pull/2515
Comment 5 Tomas Hofman 2015-08-07 08:10:21 EDT
Switching back to assigned before upstream is resolved.
Comment 11 Tomas Hofman 2015-09-03 10:36:09 EDT
Upstream rejected.

See discussion in upstream PR: https://github.com/wildfly/wildfly-core/pull/938
Comment 16 Tomas Hofman 2015-09-17 08:48:22 EDT
PR: https://github.com/jbossas/jboss-eap/pull/2558
Comment 18 Jiří Bílek 2016-01-20 04:19:08 EST
Verified with EAP 6.4.6.CP.CR2.
Comment 19 Petr Penicka 2017-01-17 06:48:17 EST
Retroactively bulk-closing issues from released EAP 6.4 cumulative patches.
Comment 20 Petr Penicka 2017-01-17 06:48:29 EST
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.