-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: trim db urls and remove special characters during backup restore #36201
Conversation
WalkthroughThe changes in this pull request focus on improving the handling of database URLs in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App
participant DB
User->>App: Request Backup
App->>App: Get DB URL
App->>App: Trim whitespace
App->>DB: Connect with clean DB URL
DB-->>App: Backup data
App-->>User: Return backup status
Assessment against linked issues
Suggested labels
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
/build-deploy-preview skip-tests=true |
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10774092346. |
Deploy-Preview-URL: https://ce-36201.dp.appsmith.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure consistent handling of undefined or null values.
The line dbUrl = env_array[i].toString().split("=")[1].trim();
assumes that the split operation results in at least two elements. If the environment variable is malformed and does not contain an "=", this will result in an undefined value, which will cause an error when trim()
is called.
To prevent runtime errors, consider checking if the split operation results in the expected number of elements before calling trim()
:
- dbUrl = env_array[i].toString().split("=")[1].trim();
+ const parts = env_array[i].toString().split("=");
+ dbUrl = parts.length > 1 ? parts[1].trim() : '';
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
dbUrl = env_array[i].toString().split("=")[1].trim(); | |
const parts = env_array[i].toString().split("="); | |
dbUrl = parts.length > 1 ? parts[1].trim() : ''; |
@@ -48,7 +48,7 @@ | |||
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good use of trim()
to ensure clean database URLs.
The addition of trim()
on the line dbUrl = dbEnvUrl.trim();
is a good practice to ensure that any leading or trailing whitespace is removed from the database URL. This change directly addresses the issue outlined in the PR summary and should help prevent errors related to improperly formatted URIs in backup operations.
However, as mentioned in the PR summary, there's a need to remove special characters as well. Consider extending this functionality to also filter out any unwanted characters that might cause parsing issues:
- dbUrl = dbEnvUrl.trim();
+ dbUrl = dbEnvUrl.trim().replace(/[^a-zA-Z0-9:/.@]+/g, '');
This regex will remove any characters that are not alphanumeric, colon, slash, period, or at symbol, which are typically safe for URIs.
Committable suggestion was skipped due to low confidence.
/build-deploy-preview skip-tests=true |
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10847567082. |
346f567
to
dd01ffd
Compare
/build-deploy-preview skip-tests=true |
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10847694151. |
/build-deploy-preview skip-tests=true |
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10847946636. |
Deploy-Preview-URL: https://ce-36201.dp.appsmith.com |
…appsmithorg#36201) fixes: appsmithorg#36176 <!-- This is an auto-generated comment: Cypress test results --> > [!WARNING] > Tests have not run on the HEAD dd01ffd 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 -->
fixes: #36176
Warning
Tests have not run on the HEAD dd01ffd yet
Fri, 13 Sep 2024 10:38:44 UTC
Summary by CodeRabbit