Skip to content

Commit

Permalink
Return valid JSON response to GetFeature request.
Browse files Browse the repository at this point in the history
While it is correct to leave trailing comma in javascript arrays, it
makes JSON invalid (namely, "features" array in response).
  • Loading branch information
Timur Sufiev committed Nov 1, 2012
1 parent 8501cb0 commit 7da3936
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/wfs/wfs_get_feature.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ static void wfs_geojson_display_results(ows * o, wfs_request * wr, mlist * reque
array *prop_table;
array_node *an;
buffer *prop, *value_enc, *geom, *id_name;
bool first;
bool first_row, first_col;
int i,j;
int geoms;
int number;
Expand Down Expand Up @@ -819,6 +819,7 @@ static void wfs_geojson_display_results(ows * o, wfs_request * wr, mlist * reque
}

prop_table = ows_psql_describe_table(o, ll->value);
first_row = true;
id_name = ows_psql_id_column(o, ll->value);
number = -1;
if (id_name && id_name->use)
Expand All @@ -827,9 +828,12 @@ static void wfs_geojson_display_results(ows * o, wfs_request * wr, mlist * reque

for (i=0 ; i < PQntuples(res) ; i++) {

first = true;
first_col = true;
geoms = 0;

if (first_row) first_row = false;
else fprintf(o->output, ",");

if ( number >= 0 ) {
buffer_add_str(id_name, "\"id\": \"");
buffer_copy(id_name, ll->value);
Expand All @@ -844,7 +848,7 @@ static void wfs_geojson_display_results(ows * o, wfs_request * wr, mlist * reque
geoms++;
} else {

if (first) first = false;
if (first_col) first_col = false;
else buffer_add_str(prop, ", \"");

buffer_copy(prop, an->key);
Expand All @@ -871,8 +875,6 @@ static void wfs_geojson_display_results(ows * o, wfs_request * wr, mlist * reque
prop->buf, "{ \"type\": \"GeometryCollection\", \"geometries\": [",
geom->buf);
}
if (j) fprintf(o->output, ",");

buffer_empty(prop);
buffer_empty(geom);
buffer_empty(id_name);
Expand Down

0 comments on commit 7da3936

Please sign in to comment.