Skip to content

Commit 8260378

Browse files
authored
Merge pull request #7381 from Countly/SER-2841-rework-replace-database-string-function-inside-plugin-manager
[SER-2841] Reworked replaceDatabaseString function
2 parents 0149cb6 + 9cf40bf commit 8260378

4 files changed

Lines changed: 35 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ Fixes:
33
- [dashboards] Unescape event segment values in meta
44

55
Enterprise fixes:
6+
- [core] Fixed replaceDatabaseString incorrectly replacing "countly" in the MongoDB username when it appears in the connection URL
67
- [data-manager] Fix validation approval button label
78
- [data-manager] Fix validation table column names
9+
- [push] Using Android specific content for Huawei messages as well
810

911
## Version 25.03.38
1012
Fixes:

package-lock.json

Lines changed: 26 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"moment": "2.30.1",
8888
"moment-timezone": "0.6.0",
8989
"mongodb": "6.20.0",
90+
"mongodb-connection-string-url": "^7.0.1",
9091
"nginx-conf": "2.1.0",
9192
"nodemailer": "8.0.1",
9293
"object-hash": "3.0.0",

plugins/pluginManager.js

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ var pluginDependencies = require('./pluginDependencies.js'),
2323
logDriverDb = log('driver:db'),
2424
exec = cp.exec,
2525
spawn = cp.spawn,
26-
configextender = require('../api/configextender');
26+
configextender = require('../api/configextender'),
27+
{ ConnectionString } = require("mongodb-connection-string-url");
2728
var pluginConfig = {};
2829

2930
/**
@@ -1768,31 +1769,10 @@ var pluginManager = function pluginManager() {
17681769
* @param {string} db - database name
17691770
* @returns {string} modified connection string
17701771
**/
1771-
this.replaceDatabaseString = function(str, db) {
1772-
if (!db) {
1773-
db = "countly";
1774-
}
1775-
var i = str.lastIndexOf('/countly');
1776-
var k = str.lastIndexOf('/' + db);
1777-
if (i !== k && i !== -1 && db) {
1778-
return str.substr(0, i) + "/" + db + str.substr(i + ('/countly').length);
1779-
}
1780-
else if (i === -1 && k === -1) {
1781-
//no db found in the string, we should insert the needed one
1782-
var urlparts = str.split("://");
1783-
if (typeof urlparts[1] === "string") {
1784-
var parts = urlparts[1].split("/");
1785-
if (parts.length === 1) {
1786-
parts[0] += "/" + db;
1787-
}
1788-
else {
1789-
parts[parts.length - 1] = db + parts[parts.length - 1];
1790-
}
1791-
urlparts[1] = parts.join("/");
1792-
}
1793-
return urlparts.join("://");
1794-
}
1795-
return str;
1772+
this.replaceDatabaseString = function(str, db = "countly") {
1773+
const connectionString = new ConnectionString(str);
1774+
connectionString.pathname = "/" + db;
1775+
return connectionString.toString();
17961776
};
17971777

17981778
this.connectToAllDatabases = async() => {

0 commit comments

Comments
 (0)