fix: trim db urls and remove special characters during backup restore (#36201)

fixes: #36176 

<!-- This is an auto-generated comment: Cypress test results  -->
> [!WARNING]
> Tests have not run on the HEAD
dd01ffd08099006721358d47ca3bb9cfbca345bc yet
> <hr>Fri, 13 Sep 2024 10:38:44 UTC
<!-- end of auto-generated comment: Cypress test results  -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved handling of database URLs by removing leading and trailing
whitespace, enhancing robustness and preventing potential issues.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Goutham Pratapa 2024-09-13 16:55:59 +05:30 committed by GitHub
parent 31a0d0e1c9
commit 9398cf48cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,7 +38,7 @@ function getDburl() {
let env_array = fs.readFileSync(Constants.ENV_PATH, 'utf8').toString().split("\n");
for (let i in env_array) {
if (env_array[i].startsWith("APPSMITH_MONGODB_URI") || env_array[i].startsWith("APPSMITH_DB_URL")) {
dbUrl = env_array[i].toString().split("=")[1];
dbUrl = env_array[i].toString().split("=")[1].trim();
break; // Break early when the desired line is found
}
}
@ -48,7 +48,7 @@ function getDburl() {
let dbEnvUrl = process.env.APPSMITH_DB_URL || process.env.APPSMITH_MONGO_DB_URI;
// Make sure dbEnvUrl takes precedence over dbUrl
if (dbEnvUrl && dbEnvUrl !== "undefined") {
dbUrl = dbEnvUrl;
dbUrl = dbEnvUrl.trim();
}
return dbUrl;
}