diff --git a/CHANGELOG.md b/CHANGELOG.md index dd8ea6d77d0..1ca43f75b0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,10 @@ Fixes: - [dashboards] Unescape event segment values in meta Enterprise fixes: +- [core] Fixed replaceDatabaseString incorrectly replacing "countly" in the MongoDB username when it appears in the connection URL - [data-manager] Fix validation approval button label - [data-manager] Fix validation table column names +- [push] Using Android specific content for Huawei messages as well ## Version 25.03.38 Fixes: diff --git a/package-lock.json b/package-lock.json index 5382f6389f2..0e2c45d69e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,6 +55,7 @@ "moment": "2.30.1", "moment-timezone": "0.6.0", "mongodb": "6.20.0", + "mongodb-connection-string-url": "^7.0.1", "nginx-conf": "2.1.0", "nodemailer": "8.0.1", "object-hash": "3.0.0", @@ -2329,9 +2330,9 @@ "license": "MIT" }, "node_modules/@types/whatwg-url": { - "version": "11.0.5", - "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", - "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-13.0.0.tgz", + "integrity": "sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q==", "license": "MIT", "dependencies": { "@types/webidl-conversions": "*" @@ -9656,6 +9657,28 @@ } }, "node_modules/mongodb-connection-string-url": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.1.tgz", + "integrity": "sha512-h0AZ9A7IDVwwHyMxmdMXKy+9oNlF0zFoahHiX3vQ8e3KFcSP3VmsmfvtRSuLPxmyv2vjIDxqty8smTgie/SNRQ==", + "license": "Apache-2.0", + "dependencies": { + "@types/whatwg-url": "^13.0.0", + "whatwg-url": "^14.1.0" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/mongodb/node_modules/@types/whatwg-url": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", + "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", + "license": "MIT", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, + "node_modules/mongodb/node_modules/mongodb-connection-string-url": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz", "integrity": "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA==", diff --git a/package.json b/package.json index 3912da1468f..4cdfe48c30e 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "moment": "2.30.1", "moment-timezone": "0.6.0", "mongodb": "6.20.0", + "mongodb-connection-string-url": "^7.0.1", "nginx-conf": "2.1.0", "nodemailer": "8.0.1", "object-hash": "3.0.0", diff --git a/plugins/pluginManager.js b/plugins/pluginManager.js index 716b67fc68a..a4ebbdffcc2 100644 --- a/plugins/pluginManager.js +++ b/plugins/pluginManager.js @@ -23,7 +23,8 @@ var pluginDependencies = require('./pluginDependencies.js'), logDriverDb = log('driver:db'), exec = cp.exec, spawn = cp.spawn, - configextender = require('../api/configextender'); + configextender = require('../api/configextender'), + { ConnectionString } = require("mongodb-connection-string-url"); var pluginConfig = {}; /** @@ -1768,31 +1769,10 @@ var pluginManager = function pluginManager() { * @param {string} db - database name * @returns {string} modified connection string **/ - this.replaceDatabaseString = function(str, db) { - if (!db) { - db = "countly"; - } - var i = str.lastIndexOf('/countly'); - var k = str.lastIndexOf('/' + db); - if (i !== k && i !== -1 && db) { - return str.substr(0, i) + "/" + db + str.substr(i + ('/countly').length); - } - else if (i === -1 && k === -1) { - //no db found in the string, we should insert the needed one - var urlparts = str.split("://"); - if (typeof urlparts[1] === "string") { - var parts = urlparts[1].split("/"); - if (parts.length === 1) { - parts[0] += "/" + db; - } - else { - parts[parts.length - 1] = db + parts[parts.length - 1]; - } - urlparts[1] = parts.join("/"); - } - return urlparts.join("://"); - } - return str; + this.replaceDatabaseString = function(str, db = "countly") { + const connectionString = new ConnectionString(str); + connectionString.pathname = "/" + db; + return connectionString.toString(); }; this.connectToAllDatabases = async() => {