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

GRASS GIS trac at osgeo.org
Wed Oct 30 11:17:44 PDT 2019


#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 at PERMANENT" --json
 {
   "module": "r.mapcalc",
   "id": "r.mapcalc_1804289383",
   "inputs":[
      {"param": "expression", "value": "month1 = -6 +
 elevation at 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 at 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"}
    ]}
 }}}

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



More information about the grass-dev mailing list