Skip to content

Commit b4b1d75

Browse files
committed
CDRIVER-3581 ignore empty int/bool uri opts
1 parent 7f785ff commit b4b1d75

File tree

2 files changed

+84
-42
lines changed

2 files changed

+84
-42
lines changed

src/libmongoc/src/mongoc/mongoc-uri.c

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,22 +1040,30 @@ mongoc_uri_apply_options (mongoc_uri_t *uri,
10401040
* also recognised as 32-bit ints.
10411041
*/
10421042
if (mongoc_uri_option_is_int64 (key)) {
1043-
if (!_mongoc_uri_parse_int64 (key, value, &v_int64)) {
1044-
goto UNSUPPORTED_VALUE;
1045-
}
1043+
if (0 < strlen (value)) {
1044+
if (!_mongoc_uri_parse_int64 (key, value, &v_int64)) {
1045+
goto UNSUPPORTED_VALUE;
1046+
}
10461047

1047-
if (!_mongoc_uri_set_option_as_int64_with_error (
1048-
uri, canon, v_int64, error)) {
1049-
return false;
1048+
if (!_mongoc_uri_set_option_as_int64_with_error (
1049+
uri, canon, v_int64, error)) {
1050+
return false;
1051+
}
1052+
} else {
1053+
MONGOC_WARNING ("Empty value provided for \"%s\"", key);
10501054
}
10511055
} else if (mongoc_uri_option_is_int32 (key)) {
1052-
if (!mongoc_uri_parse_int32 (key, value, &v_int)) {
1053-
goto UNSUPPORTED_VALUE;
1054-
}
1056+
if (0 < strlen (value)) {
1057+
if (!mongoc_uri_parse_int32 (key, value, &v_int)) {
1058+
goto UNSUPPORTED_VALUE;
1059+
}
10551060

1056-
if (!_mongoc_uri_set_option_as_int32_with_error (
1057-
uri, canon, v_int, error)) {
1058-
return false;
1061+
if (!_mongoc_uri_set_option_as_int32_with_error (
1062+
uri, canon, v_int, error)) {
1063+
return false;
1064+
}
1065+
} else {
1066+
MONGOC_WARNING ("Empty value provided for \"%s\"", key);
10591067
}
10601068
} else if (!strcmp (key, MONGOC_URI_W)) {
10611069
if (*value == '-' || isdigit (*value)) {
@@ -1070,36 +1078,40 @@ mongoc_uri_apply_options (mongoc_uri_t *uri,
10701078
}
10711079

10721080
} else if (mongoc_uri_option_is_bool (key)) {
1073-
if (0 == strcasecmp (value, "true")) {
1074-
bval = true;
1075-
} else if (0 == strcasecmp (value, "false")) {
1076-
bval = false;
1077-
} else if ((0 == strcmp (value, "1")) ||
1078-
(0 == strcasecmp (value, "yes")) ||
1079-
(0 == strcasecmp (value, "y")) ||
1080-
(0 == strcasecmp (value, "t"))) {
1081-
MONGOC_WARNING ("Deprecated boolean value for \"%s\": \"%s\", "
1082-
"please update to \"%s=true\"",
1083-
key,
1084-
value,
1085-
key);
1086-
bval = true;
1087-
} else if ((0 == strcasecmp (value, "0")) ||
1088-
(0 == strcasecmp (value, "-1")) ||
1089-
(0 == strcmp (value, "no")) || (0 == strcmp (value, "n")) ||
1090-
(0 == strcmp (value, "f"))) {
1091-
MONGOC_WARNING ("Deprecated boolean value for \"%s\": \"%s\", "
1092-
"please update to \"%s=false\"",
1093-
key,
1094-
value,
1095-
key);
1096-
bval = false;
1097-
} else {
1098-
goto UNSUPPORTED_VALUE;
1099-
}
1081+
if (0 < strlen (value)) {
1082+
if (0 == strcasecmp (value, "true")) {
1083+
bval = true;
1084+
} else if (0 == strcasecmp (value, "false")) {
1085+
bval = false;
1086+
} else if ((0 == strcmp (value, "1")) ||
1087+
(0 == strcasecmp (value, "yes")) ||
1088+
(0 == strcasecmp (value, "y")) ||
1089+
(0 == strcasecmp (value, "t"))) {
1090+
MONGOC_WARNING ("Deprecated boolean value for \"%s\": \"%s\", "
1091+
"please update to \"%s=true\"",
1092+
key,
1093+
value,
1094+
key);
1095+
bval = true;
1096+
} else if ((0 == strcasecmp (value, "0")) ||
1097+
(0 == strcasecmp (value, "-1")) ||
1098+
(0 == strcmp (value, "no")) || (0 == strcmp (value, "n")) ||
1099+
(0 == strcmp (value, "f"))) {
1100+
MONGOC_WARNING ("Deprecated boolean value for \"%s\": \"%s\", "
1101+
"please update to \"%s=false\"",
1102+
key,
1103+
value,
1104+
key);
1105+
bval = false;
1106+
} else {
1107+
goto UNSUPPORTED_VALUE;
1108+
}
11001109

1101-
if (!mongoc_uri_set_option_as_bool (uri, canon, bval)) {
1102-
return false;
1110+
if (!mongoc_uri_set_option_as_bool (uri, canon, bval)) {
1111+
return false;
1112+
}
1113+
} else {
1114+
MONGOC_WARNING ("Empty value provided for \"%s\"", key);
11031115
}
11041116

11051117
} else if (!strcmp (key, MONGOC_URI_READPREFERENCETAGS)) {

src/libmongoc/tests/json/connection_uri/valid-warnings.json

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,36 @@
6363
"options": {
6464
"wtimeoutms": 10
6565
}
66+
},
67+
{
68+
"description": "Empty integer option values are ignored",
69+
"uri": "mongodb://localhost/?maxIdleTimeMS=",
70+
"valid": true,
71+
"warning": true,
72+
"hosts": [
73+
{
74+
"type": "hostname",
75+
"host": "localhost",
76+
"port": null
77+
}
78+
],
79+
"auth": null,
80+
"options": null
81+
},
82+
{
83+
"description": "Empty boolean option value are ignored",
84+
"uri": "mongodb://localhost/?journal=",
85+
"valid": true,
86+
"warning": true,
87+
"hosts": [
88+
{
89+
"type": "hostname",
90+
"host": "localhost",
91+
"port": null
92+
}
93+
],
94+
"auth": null,
95+
"options": null
6696
}
6797
]
68-
}
98+
}

0 commit comments

Comments
 (0)