Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 98b9c56

Browse files
committed
Also allow for the fully lower case version of the option
1 parent beae7bf commit 98b9c56

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/MongoDB/Driver/Manager.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const StaticString
5151
s_MongoDBDriverManager_slaveok("slaveok"),
5252
s_MongoDBDriverManager_readpreference("readpreference"),
5353
s_MongoDBDriverManager_readpreferencetags("readpreferencetags"),
54+
s_MongoDBDriverManager_maxstalenessms("maxstalenessms"),
5455
s_MongoDBDriverManager_readPreference("readPreference"),
5556
s_MongoDBDriverManager_readPreferenceTags("readPreferenceTags"),
5657
s_MongoDBDriverManager_maxStalenessMS("maxStalenessMS"),
@@ -135,6 +136,7 @@ static bool hippo_mongo_driver_manager_apply_rp(mongoc_uri_t *uri, const Array o
135136
!options.exists(s_MongoDBDriverManager_slaveok) &&
136137
!options.exists(s_MongoDBDriverManager_readpreference) &&
137138
!options.exists(s_MongoDBDriverManager_readpreferencetags) &&
139+
!options.exists(s_MongoDBDriverManager_maxstalenessms) &&
138140
!options.exists(s_MongoDBDriverManager_readPreference) &&
139141
!options.exists(s_MongoDBDriverManager_readPreferenceTags) &&
140142
!options.exists(s_MongoDBDriverManager_maxStalenessMS)
@@ -197,15 +199,23 @@ static bool hippo_mongo_driver_manager_apply_rp(mongoc_uri_t *uri, const Array o
197199
}
198200

199201
/* Handle maxStalenessMS, and make sure it is not combined with PRIMARY readPreference */
200-
if (options.exists(s_MongoDBDriverManager_maxStalenessMS) && options[s_MongoDBDriverManager_maxStalenessMS].isInteger()) {
202+
if (
203+
(options.exists(s_MongoDBDriverManager_maxstalenessms) && options[s_MongoDBDriverManager_maxstalenessms].isInteger())
204+
||
205+
(options.exists(s_MongoDBDriverManager_maxStalenessMS) && options[s_MongoDBDriverManager_maxStalenessMS].isInteger())
206+
) {
201207
if (mongoc_read_prefs_get_mode(new_rp) == MONGOC_READ_PRIMARY) {
202208
throw MongoDriver::Utils::throwInvalidArgumentException("Primary read preference mode conflicts with maxStalenessMS");
203209
mongoc_read_prefs_destroy(new_rp);
204210

205211
return false;
206212
}
207213

208-
mongoc_read_prefs_set_max_staleness_ms(new_rp, (int32_t) options[s_MongoDBDriverManager_maxStalenessMS].toInt64());
214+
if (options.exists(s_MongoDBDriverManager_maxstalenessms)) {
215+
mongoc_read_prefs_set_max_staleness_ms(new_rp, (int32_t) options[s_MongoDBDriverManager_maxstalenessms].toInt64());
216+
} else {
217+
mongoc_read_prefs_set_max_staleness_ms(new_rp, (int32_t) options[s_MongoDBDriverManager_maxStalenessMS].toInt64());
218+
}
209219
}
210220

211221
/* This may be redundant in light of the check for primary with tags,

tests/MongoDBDriverManager_maxStalenessMS-001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ MongoDB\Driver\Manager: maxStalenessMS
55
// They both should work, and produce no output. We're not testing whether the flag actually does something
66
$manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY&maxStalenessMS=1231");
77
$manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY", [ 'maxStalenessMS' => 1231 ] );
8+
$manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY&maxstalenessms=1231");
9+
$manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY", [ 'maxstalenessms' => 1231 ] );
810
?>
911
==DONE==
1012
--EXPECTF--

tests/MongoDBDriverManager_maxStalenessMS_error-001.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,32 @@
22
MongoDB\Driver\Manager: maxStalenessMS
33
--FILE--
44
<?php
5+
try {
6+
$manager = new MongoDB\Driver\Manager("mongodb://localhost/?maxstalenessms=1231");
7+
} catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) {
8+
echo $e->getMessage(), "\n";
9+
}
10+
511
try {
612
$manager = new MongoDB\Driver\Manager("mongodb://localhost/?maxStalenessMS=1231");
713
} catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) {
814
echo $e->getMessage(), "\n";
915
}
1016

17+
try {
18+
$manager = new MongoDB\Driver\Manager("mongodb://localhost/", [ 'maxstalenessms' => 1231 ] );
19+
} catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
1123
try {
1224
$manager = new MongoDB\Driver\Manager("mongodb://localhost/", [ 'maxStalenessMS' => 1231 ] );
1325
} catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) {
1426
echo $e->getMessage(), "\n";
1527
}
1628
?>
1729
--EXPECTF--
30+
Failed to parse MongoDB URI: 'mongodb://localhost/?maxstalenessms=1231'
1831
Failed to parse MongoDB URI: 'mongodb://localhost/?maxStalenessMS=1231'
1932
Primary read preference mode conflicts with maxStalenessMS
33+
Primary read preference mode conflicts with maxStalenessMS

0 commit comments

Comments
 (0)