LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
175 stars 31 forks source link

Empty paths are ill-defined in Catmandu and are buggy in some cases. #398

Closed phochste closed 1 year ago

phochste commented 1 year ago

There is currently no good mechanism in Catmandu to adress JSON properties with empty keys. Examples:

example 1

{ "": "empty"}

example 2

{
  "x": {
    "": "empty"
  }
}

For both examples removing, changing or adding information to path containing empty keys results in null operations or bugs.

E.g.

$ echo '{ "": "empty"}' | catmandu convert JSON --fix "remove_field('',)"
Use of uninitialized value $key in string eq at /Users/hochsten/.plenv/versions/5.24.0/lib/perl5/site_perl/5.24.0/Catmandu/Path/simple.pm line 401.
Use of uninitialized value $key in string eq at /Users/hochsten/.plenv/versions/5.24.0/lib/perl5/site_perl/5.24.0/Catmandu/Path/simple.pm line 401.
Use of uninitialized value $key in string eq at /Users/hochsten/.plenv/versions/5.24.0/lib/perl5/site_perl/5.24.0/Catmandu/Path/simple.pm line 401.
[{"":"empty"}]

$ echo '{ "": "empty"}' | catmandu convert JSON --fix "move_field('','y')"
Use of uninitialized value $key in string eq at /Users/hochsten/.plenv/versions/5.24.0/lib/perl5/site_perl/5.24.0/Catmandu/Path/simple.pm line 401.
Use of uninitialized value $key in string eq at /Users/hochsten/.plenv/versions/5.24.0/lib/perl5/site_perl/5.24.0/Catmandu/Path/simple.pm line 401.
Use of uninitialized value $key in string eq at /Users/hochsten/.plenv/versions/5.24.0/lib/perl5/site_perl/5.24.0/Catmandu/Path/simple.pm line 401.
[{"y":{"":"empty"},"":"empty"}]

echo '{ "": "empty"}' | catmandu convert JSON --fix "upcase('')"
[{"":"empty"}]

There is also no way to generate using the basic Catmandu fixes data which contain empty fields.

See also: https://github.com/LibreCat/Catmandu/pull/397