-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: trim db urls and remove special characters during backup restore #36201
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of The addition of 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.
|
||
| } | ||
| return dbUrl; | ||
| } | ||
|
|
||
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 whentrim()is called.To prevent runtime errors, consider checking if the split operation results in the expected number of elements before calling
trim():Committable suggestion