test-fullautomation / python-jsonpreprocessor

A preprocessor for json files
Apache License 2.0
2 stars 2 forks source link

Side effects of latest changes #242

Closed HolQue closed 1 month ago

HolQue commented 3 months ago

Hi Son,

the stabi branch changes from 15.03.2024 solved some issues. But these changes also caused a lot of side effects.

Some of them are improvements, some of them are a deterioration, some of them are neutral.

I have no idea what is the best way to handle this.

Please find below a list of some more striking differences:

(1)

"testlist" : [1,2,3],
"value"    : ${testlist}[]

Previous result: 'Expression '${testlist}[]' cannot be evaluated. Reason: Empty pair of square brackets detected.'

New result:

[DICT] (2/1) > {testlist} [LIST] (3/1) > [INT]  :  1
[DICT] (2/1) > {testlist} [LIST] (3/2) > [INT]  :  2
[DICT] (2/1) > {testlist} [LIST] (3/3) > [INT]  :  3
[DICT] (2/2) > {value} [STR]  :  '[1, 2, 3][]'

First result is the better one.

(2)

"testlist" : [1,2,3],
"value"    : ${testlist}[${}]

Previous result: 'Invalid parameter format: ${testlist}[${}]'

New result: 'Infinity loop detection while handling the parameter '${testlist}[${}]'.'

When it's already possible to detect an endless loop, I would prefer an "invalid expression" error. At least the AIO version 0.11 should not contain "Infinity loop detection" any more.

(3)

"dict_param" : {"A" : 1 , "B" : 2}
"list_param" : ["A", "B", "C"]
"val1"       : "${list_param[1]}"

Previous result: 'Invalid syntax: Found index inside curly brackets in line '"val1" : "${list_param[1]}"'. Indices in square brackets have to be placed outside the curly brackets.'

New result: Expecting ',' delimiter: line 3 column 4 (char 43)'

The new result makes no sense. The previous result is completely fine. Please recover.

(4)

"testlist" : ["A", "B", "C", "D"],
"index1"   : 1,
"index2"   : 3,
"param3"   : ${testlist}[${index1}:${index2}]

Previous result: 'Invalid nested parameter format: ${testlist}[${index1} - The double quotes are missing!!!'

New result: Expecting ',' delimiter: line 5 column 39 (char 116)'

Expected: Slicing not supported

(5)

"testlist" : ["A", "B", "C", "D"],
"param2"   : ${testlist}[+1]

Previous result: 'Invalid nested parameter format: ${testlist}[+1] - The double quotes are missing!!!'

New result:

[DICT] (2/1) > {testlist} [LIST] (4/1) > [STR]  :  'A'
[DICT] (2/1) > {testlist} [LIST] (4/2) > [STR]  :  'B'
[DICT] (2/1) > {testlist} [LIST] (4/3) > [STR]  :  'C'
[DICT] (2/1) > {testlist} [LIST] (4/4) > [STR]  :  'D'
[DICT] (2/2) > {param2} [STR]  :  '['A', 'B', 'C', 'D'][+1]'

Expected: '+' character should not harm the index

(6)

"param1" : "value1",
"param2" : ${param1

Previous result: 'Invalid parameter format in line: "param2" : ${param1'

New result: 'Invalid nested parameter format: ${param1 - The double quotes are missing!!!'

This is not 'nested' (see https://github.com/test-fullautomation/python-jsonpreprocessor/issues/239). The problem here is not a missing double quote but a missing closed curly bracket.

(7)

"param1" : "value1",
"param2" : "${param1"

Previous result: 'Invalid parameter format in line: "param2" : "${param1"'

New result: 'Invalid nested parameter format: ${param1 - The double quotes are missing!!!'

Here the double quotes are set, not missing. A closing curly bracket is missing instead.

(8)

"listparam" : ["A","B","C"],
"param" : ${listparam}0]

Previous result: 'Invalid nested parameter format: ${listparam}0 - The double quotes are missing!!!'

New result: Expecting ',' delimiter: line 3 column 29 (char 62)'

In case of extra content '0]' outside dollar operator expressions, this expression has to be set in quotes. Therefore the first error message is the better one. The new error message makes no sense.

(9)

"listparam" : ["A","B","C"],
"param" : "${${listparam}[0]"

Previous result:

'Invalid syntax! One or more than one opened or closed curly bracket is missing in expression '${${listparam}[0]'.
           Please check the configuration file of the executed test!'

New result: 'Invalid nested parameter format: ${${listparam}[0]'

Previous result is completely fine. Please recover.

(10)

"listparam" : ["A","B","C"],
${listparam}0] : "value"

Previous result: 'Invalid nested parameter format: ${listparam}0 - The double quotes are missing!!!'

New result: Expecting ':' delimiter: line 3 column 16 (char 49)'

Please recover the first result. The new result makes no sense.

(11)

"indexP" : 0,
"keyP"   : "A",
"dictP"  : {"A" : 0, "B" : 1},
"listP"  : ["A", "B"],

"params" : {${indexP} : "002",
            "003" : ["004", {"005" : "006",
            ...

Previous result: 'Invalid nested parameter format: {${indexP} - The double quotes are missing!!!'

New result: Expecting ',' delimiter: line 6 column 28 (char 125)'

The new result makes no sense. The first result is mostly OK. A dollar operator expression at the position of a key inside a dictionary makes no sense. Therefore must be encapsulated in quotes. But this would be the creation of a key based on a parameter - and it is already decided that this should not be allowed.

And this part '{${indexP}' is not directly the part that causes the problem, because the first opening curly bracket belongs to the dictionary, and not to the dictionary key.

Expected is something like: Definition of key names based on parameters, are not allowed (${indexP}).

(12)

"params" : {"001" : ${keyP,
            "003" : ["004", {"005" : "006",
            ...

Previous result: 'Invalid parameter format in line: "params" : {"001" : ${keyP,'

New result: 'Invalid nested parameter format: ${keyP - The double quotes are missing!!!'

Because '${keyP,' is not wrapped in double quotes, I would expect that the trailing comma is part of the syntax. In this case it's obvious that a closing curly bracket is missing at end of 'keyP'.

And with double quotes "${keyP" it's the same.

(13)

"params" : {"001" : "002",
            "003" : [${keyP, {"005" : "006",
            ...

Previous result: 'Invalid parameter format in line: "003" : [${keyP, {"005" : "006",'

New result: A list element '${keyP' as string.

Like in (12) a closing curly bracket is missing. This is invalid. Therefore the previous result is the better one.

An opening element '${' should always require a corresponding closing element '}'.

(14)

"params" : {"${dictP}[${keyP]" : "002",
            "003" : ["004", {"005" : "006",
            ...

Previous result:

'Invalid syntax! One or more than one opened or closed curly bracket is missing in expression '${dictP}[${keyP]'.
           Please check the configuration file of the executed test!'

New result: 'Invalid nested parameter format: ${dictP}[${keyP]'

A closing curly bracket is missing. Please recover the previous result.

namsonx commented 2 months ago

Hello Holger,

Thank you very much for your findings! I'm still working on case by case. For the case (3), it contradicts the comment you mentioned in ticket #189

Conclusion: All error messages are correct. But what makes me worried is that the order of the error detection depends on the complexity of the affected expressions. In my opinion this should not happen. Missing delimiters should always have a higher priority in error handling than errors inside expressions that are separated by these delimiters.

And in case number (3)

"dict_param" : {"A" : 1 , "B" : 2}
"list_param" : ["A", "B", "C"]
"val1"       : "${list_param[1]}"

This is missing delimiters, and this error message is in high priority.

Thank you, Son

namsonx commented 2 months ago

We will ignore the case (3)

namsonx commented 2 months ago

Hello Holger,

For the case (11)

"indexP" : 0,
"keyP"   : "A",
"dictP"  : {"A" : 0, "B" : 1},
"listP"  : ["A", "B"],

"params" : {${indexP} : "002",
            "003" : ["004", {"005" : "006",
            ...

This is similar to the case (3) I mentioned in the previous comment. There is an invalid JSON syntax in the line "params" : {${indexP} : "002", and it will be in high priority as your comment in ticket #189

Thank you, Son

namsonx commented 2 months ago

Hello Holger,

I solved all the side effects you mentioned in this ticket, now the JP output for these cases are: (1)

"testlist" : [1,2,3],
"value"    : ${testlist}[]

Output: Expression '${testlist}[]' cannot be evaluated. Reason: A pair of square brackets is empty or contains not allowed characters.

(2)

"testlist" : [1,2,3],
"value"    : ${testlist}[${}]

Output: Expression '${testlist}[${}]' cannot be evaluated. Reason: A pair of curly brackets is empty or contains not allowed characters.

(4)

"testlist" : ["A", "B", "C", "D"],
"index1"   : 1,
"index2"   : 3,
"param3"   : ${testlist}[${index1}:${index2}]

Output: Slicing is not supported! Please update the expression '${testlist}[${index1}:${index2}]'.

(5)

"testlist" : ["A", "B", "C", "D"],
"param2"   : ${testlist}[+1]

Output: param2 : B - <class 'str'>

(6)

"param1" : "value1",
"param2" : ${param1

Output: Invalid parameter format: ${param1 - Closed curly bracket is missing.

(7)

"param1" : "value1",
"param2" : "${param1"

Output: Invalid parameter format: ${param1 - Closed curly bracket is missing.

(8)

"listparam" : ["A","B","C"],
"param" : ${listparam}0]

Output: Invalid parameter format: ${listparam}0]

(9)

"listparam" : ["A","B","C"],
"param" : "${${listparam}[0]"

Output: Invalid syntax! One or more than one opened or closed curly bracket is missing in expression '${${listparam}[0]'.

(10)

"listparam" : ["A","B","C"],
${listparam}0] : "value"

Output: Invalid parameter format: ${listparam}0]

(12)

"params" : {"001" : ${keyP,
            "003" : ["004", {"005" : "006",
            ...

Output: Invalid parameter format: ${keyP - Closed curly bracket is missing.

(13)

"params" : {"001" : "002",
            "003" : [${keyP, {"005" : "006",
            ...

Output: Invalid parameter format: ${keyP - Closed curly bracket is missing.

(14)

"params" : {"${dictP}[${keyP]" : "002",
            "003" : ["004", {"005" : "006",
            ...

Output: Invalid syntax! One or more than one opened or closed curly bracket is missing in expression '${dictP}[${keyP]'.

Thank you, Son

HolQue commented 2 months ago

Hi Son,

very good! Much better now.

Retest successful. Issue can be closed.

test-fullautomation commented 1 month ago

integrated in RobotFramework AIO 0.11.0