Skip to content

Commit 182f2b0

Browse files
committed
CDRIVER-2158 preserve case of domain socket paths
1 parent 6039a1a commit 182f2b0

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Next Release
3030
* Special characters in username, password and other values must be url encoded
3131
* Unsupported connection string options now issue warnings
3232
* Boolean values can now be represented as true/yes/y/t/1 and false/no/n/f/0.
33+
* Case is now preserved in Unix domain paths.
3334
* New function mongoc_cursor_error_document provides access to server's error
3435
reply if a query or command fails.
3536
* mongoc_gridfs_find_one_with_opts optimized to use limit 1.

src/mongoc/mongoc-uri-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BSON_BEGIN_DECLS
3030
bool
3131
mongoc_uri_append_host (mongoc_uri_t *uri, const char *host, uint16_t port);
3232
bool
33-
mongoc_uri_parse_host (mongoc_uri_t *uri, const char *str);
33+
mongoc_uri_parse_host (mongoc_uri_t *uri, const char *str, bool downcase);
3434

3535
int32_t
3636
mongoc_uri_get_local_threshold_option (const mongoc_uri_t *uri);

src/mongoc/mongoc-uri.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ mongoc_uri_append_host (mongoc_uri_t *uri, const char *host, uint16_t port)
8686
}
8787

8888
link_ = (mongoc_host_list_t *) bson_malloc0 (sizeof *link_);
89-
mongoc_lowercase (host, link_->host);
89+
bson_strncpy (link_->host, host, sizeof link_->host);
9090
if (strchr (host, ':')) {
9191
bson_snprintf (link_->host_and_port,
9292
sizeof link_->host_and_port,
@@ -262,6 +262,7 @@ mongoc_uri_parse_host6 (mongoc_uri_t *uri, const char *str)
262262
return false;
263263
}
264264

265+
mongoc_lowercase (hostname, hostname);
265266
r = mongoc_uri_append_host (uri, hostname, port);
266267
bson_free (hostname);
267268

@@ -270,7 +271,7 @@ mongoc_uri_parse_host6 (mongoc_uri_t *uri, const char *str)
270271

271272

272273
bool
273-
mongoc_uri_parse_host (mongoc_uri_t *uri, const char *str)
274+
mongoc_uri_parse_host (mongoc_uri_t *uri, const char *str, bool downcase)
274275
{
275276
uint16_t port;
276277
const char *end_host;
@@ -310,6 +311,10 @@ mongoc_uri_parse_host (mongoc_uri_t *uri, const char *str)
310311
return false;
311312
}
312313

314+
if (downcase) {
315+
mongoc_lowercase (hostname, hostname);
316+
}
317+
313318
r = mongoc_uri_append_host (uri, hostname, port);
314319
bson_free (hostname);
315320

@@ -341,11 +346,11 @@ mongoc_uri_parse_hosts (mongoc_uri_t *uri, const char *str, const char **end)
341346
*/
342347

343348
again:
344-
if (((*str == '/') && (sock = strstr (str, ".sock"))) &&
349+
if (((!strncmp (str, "%2F", 3)) && (sock = strstr (str, ".sock"))) &&
345350
(!(tmp = strstr (str, ",")) || (tmp > sock)) &&
346351
(!(tmp = strstr (str, "?")) || (tmp > sock))) {
347352
s = bson_strndup (str, sock + 5 - str);
348-
if (!mongoc_uri_parse_host (uri, s)) {
353+
if (!mongoc_uri_parse_host (uri, s, false /* downcase */)) {
349354
bson_free (s);
350355
return false;
351356
}
@@ -358,7 +363,7 @@ mongoc_uri_parse_hosts (mongoc_uri_t *uri, const char *str, const char **end)
358363
}
359364
*end = str;
360365
} else if ((s = scan_to_unichar (str, ',', "/", &end_hostport))) {
361-
if (!mongoc_uri_parse_host (uri, s)) {
366+
if (!mongoc_uri_parse_host (uri, s, true /* downcase */)) {
362367
bson_free (s);
363368
return false;
364369
}
@@ -368,15 +373,15 @@ mongoc_uri_parse_hosts (mongoc_uri_t *uri, const char *str, const char **end)
368373
goto again;
369374
} else if ((s = scan_to_unichar (str, '/', "", &end_hostport)) ||
370375
(s = scan_to_unichar (str, '?', "", &end_hostport))) {
371-
if (!mongoc_uri_parse_host (uri, s)) {
376+
if (!mongoc_uri_parse_host (uri, s, true /* downcase */)) {
372377
bson_free (s);
373378
return false;
374379
}
375380
bson_free (s);
376381
*end = end_hostport;
377382
return true;
378383
} else if (*str) {
379-
if (!mongoc_uri_parse_host (uri, str)) {
384+
if (!mongoc_uri_parse_host (uri, str, true /* downcase */)) {
380385
return false;
381386
}
382387
*end = str + strlen (str);

tests/test-mongoc-uri.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,13 @@ test_mongoc_uri_functions (void)
679679
mongoc_database_destroy (db);
680680
mongoc_client_destroy (client);
681681
mongoc_uri_destroy (uri);
682+
683+
uri = mongoc_uri_new ("mongodb://%2Ftmp%2FMongoDB-27017.sock/");
684+
ASSERT_CMPSTR (mongoc_uri_get_hosts (uri)->host, "/tmp/MongoDB-27017.sock");
685+
ASSERT_CMPSTR (mongoc_uri_get_hosts (uri)->host_and_port,
686+
"/tmp/MongoDB-27017.sock");
687+
688+
mongoc_uri_destroy (uri);
682689
}
683690

684691
static void
@@ -812,7 +819,7 @@ test_mongoc_host_list_from_string (void)
812819

813820
ASSERT (_mongoc_host_list_from_string (&host_list, "[::1]"));
814821
ASSERT_CMPSTR (host_list.host_and_port, "[::1]:27017");
815-
ASSERT_CMPSTR (host_list.host, "::1"); /* no "[" or "]" */
822+
ASSERT_CMPSTR (host_list.host, "::1"); /* no "[" or "]" */
816823
ASSERT (host_list.port == 27017);
817824

818825
ASSERT (_mongoc_host_list_from_string (&host_list, "[Fe80::1]:1234"));

0 commit comments

Comments
 (0)