Opened 5 years ago

Closed 5 years ago

#3928 closed defect (fixed)

parser: --json bug with white space in parameter values

Reported by: neteler Owned by: grass-dev@…
Priority: normal Milestone: 7.8.1
Component: LibGIS Version: git-releasebranch78
Keywords: parser Cc:
CPU: Unspecified Platform: Unspecified

Description

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

Change History (3)

comment:1 by neteler, 5 years ago

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", "type":"vector"},
      "param": "vector", "value": "antenna_positions"}
   ]}
Note: See TracTickets for help on using tickets.