Skip to content

Commit 5dfb62f

Browse files
IslandRhythmsvkarpov15
authored andcommittedFeb 25, 2024·
test: fix issues with cherry-picking #13376 to 6.x
1 parent 352137b commit 5dfb62f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
 

‎lib/helpers/processConnectionOptions.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ function processConnectionOptions(uri, options) {
99
? opts.readPreference
1010
: getUriReadPreference(uri);
1111

12+
const clonedOpts = clone(opts);
1213
const resolvedOpts = (readPreference && readPreference !== 'primary' && readPreference !== 'primaryPreferred')
13-
? resolveOptsConflicts(readPreference, opts)
14-
: opts;
14+
? resolveOptsConflicts(readPreference, clonedOpts)
15+
: clonedOpts;
1516

16-
return clone(resolvedOpts);
17+
return resolvedOpts;
1718
}
1819

1920
function resolveOptsConflicts(pref, opts) {

‎test/connection.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -1537,4 +1537,13 @@ describe('connections:', function() {
15371537
});
15381538
assert.deepEqual(m.connections.length, 0);
15391539
});
1540+
1541+
describe('processConnectionOptions', function() {
1542+
it('should not throw an error when attempting to mutate unmutable options object gh-13335', async function() {
1543+
const m = new mongoose.Mongoose();
1544+
const opts = Object.preventExtensions({});
1545+
const conn = await m.connect('mongodb://localhost:27017/db?retryWrites=true&w=majority&readPreference=secondaryPreferred', opts);
1546+
assert.ok(conn);
1547+
});
1548+
});
15401549
});

0 commit comments

Comments
 (0)
Please sign in to comment.