Geobuf testing exposes a bug in type coercion of 0.0 to boolean

This commit is contained in:
Eric Fischer 2017-08-29 11:41:57 -07:00
parent 7c031a9796
commit 4b66aa828d
5 changed files with 5 additions and 5 deletions

@ -156,7 +156,7 @@ resolution is obtained than by using a smaller _maxzoom_ or _detail_.
* `-X` or `--exclude-all`: Exclude all properties and encode only geometries
* `-T`_attribute_`:`_type_ or `--attribute-type=`_attribute_`:`_type_: Coerce the named feature _attribute_ to be of the specified _type_.
The _type_ may be `string`, `float`, `int`, or `bool`.
If the type is `bool`, then original attributes of `0`, `false`, `null`, or the empty string become `false`, and otherwise become `true`.
If the type is `bool`, then original attributes of `0` (or, if numeric, `0.0`, etc.), `false`, `null`, or the empty string become `false`, and otherwise become `true`.
If the type is `float` or `int` and the original attribute was non-numeric, it becomes `0`.
If the type is `int` and the original attribute was floating-point, it is rounded to the nearest integer.

@ -173,7 +173,7 @@ resolution is obtained than by using a smaller \fImaxzoom\fP or \fIdetail\fP\&.
.IP \(bu 2
\fB\fC\-T\fR\fIattribute\fP\fB\fC:\fR\fItype\fP or \fB\fC\-\-attribute\-type=\fR\fIattribute\fP\fB\fC:\fR\fItype\fP: Coerce the named feature \fIattribute\fP to be of the specified \fItype\fP\&.
The \fItype\fP may be \fB\fCstring\fR, \fB\fCfloat\fR, \fB\fCint\fR, or \fB\fCbool\fR\&.
If the type is \fB\fCbool\fR, then original attributes of \fB\fC0\fR, \fB\fCfalse\fR, \fB\fCnull\fR, or the empty string become \fB\fCfalse\fR, and otherwise become \fB\fCtrue\fR\&.
If the type is \fB\fCbool\fR, then original attributes of \fB\fC0\fR (or, if numeric, \fB\fC0.0\fR, etc.), \fB\fCfalse\fR, \fB\fCnull\fR, or the empty string become \fB\fCfalse\fR, and otherwise become \fB\fCtrue\fR\&.
If the type is \fB\fCfloat\fR or \fB\fCint\fR and the original attribute was non\-numeric, it becomes \fB\fC0\fR\&.
If the type is \fB\fCint\fR and the original attribute was floating\-point, it is rounded to the nearest integer.
.RE

@ -622,7 +622,7 @@ void coerce_value(std::string const &key, int &vt, std::string &val, std::map<st
}
}
} else if (a->second == mvt_bool) {
if (val == "false" || val == "0" || val == "null" || val.size() == 0) {
if (val == "false" || val == "0" || val == "null" || val.size() == 0 || (vt == mvt_double && atof(val.c_str()) == 0)) {
vt = mvt_bool;
val = "false";
} else {

@ -7,7 +7,7 @@
{ "type": "Feature", "properties": { "booltype": "false", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
{ "type": "Feature", "properties": { "booltype": 1, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
{ "type": "Feature", "properties": { "booltype": 0.0, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
{ "type": "Feature", "properties": { "booltype": 0.0, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
{ "type": "Feature", "properties": { "booltype": "yes", "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
{ "type": "Feature", "properties": { "booltype": [ 2, 3 ], "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }
{ "type": "Feature", "properties": { "stringtype": null, "expect": "null" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } }

@ -30,7 +30,7 @@
,
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
,
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
,
{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } }
,