metafacture / metafacture-fix

Work in progress towards an implementation of the Fix language for Metafacture
Apache License 2.0
6 stars 2 forks source link

Writing into non-existing arrays with $last, $first and *-wildcard should be skipped? #369

Open TobiasNx opened 4 days ago

TobiasNx commented 4 days ago

Came up within #368 but is not part of the changes of the related pr this is current master behaviour :

While reading a path with one of the following array wildcards $last, $first and * skips the step due to no existing basis for reading, writing new values with these array wildcards does not and creates a new element/array with one of wildcard as part of the pathnames

in:
---
a: "Faust" 

copy_field

fix:
copy_field("a","test.*.test")
out:
---
a: "Faust"
test:
  '*':
    test: "Faust"

add_field

fix:
add_field("test.$last.test","a")
out:
---
a: "Faust"
test:
  $last:
    test: "a"

set_array

fix:
set_array("test.$first.test","a")
out:
---
a: "Faust"
test:
  $first:
    test: "a"

In my opinion these creations should be skipped due to non existing arrays and only $append/$prepend should create pathes.

This is connected to: https://github.com/metafacture/metafacture-fix/issues/161

TobiasNx commented 4 days ago

It also seems that catmandu is not that consistend in its behaviour:

https://github.com/TobiasNx/Catmandu-Testing/tree/master/ArrayHandling

$append does not create new array with set_array $last/$first create new arrays with given values as $append would

*only works it array exists

fsteeg commented 2 days ago

[in catmandu] $last/$first create new arrays with given values as $append would

Then we should do the same here, right?

TobiasNx commented 2 days ago

[in catmandu] $last/$first create new arrays with given values as $append would

Then we should do the same here, right?

To be honest, I am not in favour of this even though Catmandu does this BUT it is not consitent. And Catmandu itself seems not to be consistent with this.

I prefer the behaviour that $last and $first only can do anything if the referred array exists since it is a relational statement imo.