test-fullautomation / python-jsonpreprocessor

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

Dynamic key names shall be blocked, if it would cause creation of a new key (or subkey) #270

Open test-fullautomation opened 1 month ago

test-fullautomation commented 1 month ago

Expressions on left side which contain $-operators inside double quotes shall be generally blocked. e.g. "${param}" : 1 "prefix_${param}_suffix" : 1

Goal is to reduce stabilization and testing effort. Later when all other features are stable we can create a task to provide this feature.

$-operator as part of a string as value shall be supported, if the data type is a simple data type.

test-fullautomation commented 1 month ago

Hi @namsonx , plesae consider this from now onwards for all your activities. Previous tickets may deviate or may be invalid. Thank you, Thomas

namsonx commented 3 weeks ago

Hello Thomas,

I created the commit 31b8cd50baa to block dynamic key names, the Selftest is also updated.

Thank you, Son

HolQue commented 1 week ago

Retest successful. Issue can be closed.

HolQue commented 1 week ago

It is still possible and allowed to do this:

"strval"  : "A",
"dictval" : {"A_2" : 1},
${dictval}['${strval}_2'] : 2

Because of a key with name "A_2" already exists.

Result:

{'dictval': {'A_2': 2}, 'strval': 'A'}

But it is not allowed to do this:

"strval" : "B",
${dictval}['${strval}_2'] : 2

Because of a key with name "B_2" does not exist (the entire dictionary does not exist).

Result:

Error: 'A substitution in key names is not allowed! Please update the key name "${strval}_2"'!

Impact: A parameter substitution inside key names is not forbidden generally. It's only forbidden in case of a key with the resulting name does not exist already. Therefore the error message needs to be reworked.

For example:

Identified dynamic name of a key that does not exist. But new keys can only be created based on hard coded names.
Please remove all dollar operator expressions inside the key name "${strval}_2".

I will update the documentation in this way:

To use dynamic key names is allowed, but only in case of a key with the resulting name does exist already. Therefore this mechanism can be used to overwrite the value of existing keys, but cannot be used to create new keys.

namsonx commented 1 week ago

Hello Holger,

Thank you for your very interesting finding! I think we just simply block all instances of dynamic key names, is that Okie?

Thank you, Son

namsonx commented 5 days ago

Hello Holger,

I pushed the change to stabi branch to implement the cases you mentioned in your comment.

Thank you, Son

HolQue commented 3 days ago

Retest successful. Issue can be closed.