[GRASS-dev] [GRASS GIS] #3928: parser: --json bug with white space in parameter values

#3928: parser: --json bug with white space in parameter values
-------------------------+---------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.8.1
Component: LibGIS | Version: git-releasebranch78
Keywords: parser | CPU: Unspecified
Platform: Unspecified |
-------------------------+---------------------------------
At time the JSON support stumbles over white space:

Consider:

{{{
GRASS 7.8.1dev (nc_spm_08):~ > v.db.update map=antenna_position
column='z_antenna' qcolumn='z + 2.00' --json
{
   "module": "v.db.update",
   "id": "v.db.update_1804289383",
   "inputs":[
      {"param": "map", "value": "antenna_position"},
      {"param": "layer", "value": "1"},
      {"param": "column", "value": "z_antenna"},
      {"param": "query_column", "value": "z"}
    ]}
}}}

The part ` + 2.00` does not survive...

The issue is somewhere in
https://github.com/OSGeo/grass/blob/master/lib/gis/parser_json.c

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3928&gt;
GRASS GIS <https://grass.osgeo.org>

#3928: parser: --json bug with white space in parameter values
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.8.1
Component: LibGIS | Version: git-releasebranch78
Resolution: | Keywords: parser
       CPU: Unspecified | Platform: Unspecified
--------------------------+---------------------------------

Comment (by neteler):

The problem is the use of G_tokenizer() with "+" in line:

https://github.com/OSGeo/grass/blob/master/lib/gis/parser_json.c#L347

A solution might be to switch to "@" in order to not confuse with
algebraic functions.

Patch:

{{{
diff --git a/lib/gis/parser_json.c b/lib/gis/parser_json.c
index a0d808f1f..93d927067 100644
--- a/lib/gis/parser_json.c
+++ b/lib/gis/parser_json.c
@@ -344,7 +344,7 @@ void check_create_import_opts(struct Option *opt, char
*element, FILE *fp)
      int has_import = 0;
      char **tokens;

- tokens = G_tokenize(opt->answer, "+");
+ tokens = G_tokenize(opt->answer, "@");
      while (tokens[i]) {
          G_chop(tokens[i]);
          i++;
}}}

Then the following works fine:

{{{
GRASS 7.9.dev (nc_spm_08):~ > r.mapcalc "month1 = -6 +
elevation@PERMANENT" --json
{
   "module": "r.mapcalc",
   "id": "r.mapcalc_1804289383",
   "inputs":[
      {"param": "expression", "value": "month1 = -6 +
elevation@PERMANENT"},
      {"param": "region", "value": "current"}
    ]}
}}}

as well as

{{{
v.db.update map=antenna_position column='z_antenna' qcolumn='z + 2.00'
--json
{
   "module": "v.db.update",
   "id": "v.db.update_1804289383",
   "inputs":[
      {"param": "map", "value": "antenna_position"},
      {"param": "layer", "value": "1"},
      {"param": "column", "value": "z_antenna"},
      {"param": "layer", "value": "z + 2.00"}
    ]}
}}}

as well as for actinia's importer:

{{{
importer vector=antenna_positions@https://example.org/myfile.gpkg --json
{
   "module": "importer",
   "id": "importer_1804289383",
   "inputs":[
      {"import_descr": {"source":"https://example.org/myfile.gpkg&quot;,
"type":"vector"},
       "param": "vector", "value": "antenna_positions"}
    ]}
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3928#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3928: parser: --json bug with white space in parameter values
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.8.1
Component: LibGIS | Version: git-releasebranch78
Resolution: | Keywords: parser
       CPU: Unspecified | Platform: Unspecified
--------------------------+---------------------------------

Comment (by neteler):

New PR at https://github.com/OSGeo/grass/pull/175

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3928#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3928: parser: --json bug with white space in parameter values
--------------------------+---------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.8.1
Component: LibGIS | Version: git-releasebranch78
Resolution: fixed | Keywords: parser
       CPU: Unspecified | Platform: Unspecified
--------------------------+---------------------------------
Changes (by neteler):

* status: new => closed
* resolution: => fixed

Comment:

Merged in

- master:
https://github.com/OSGeo/grass/commit/21fcb06088e6a149f48fb4c650228de367725a06
- relbranch78:
https://github.com/OSGeo/grass/commit/2a10f3a713a82671384820f4399adafeae2beeec

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3928#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>