-
Notifications
You must be signed in to change notification settings - Fork 106
Description
Problem Description
During PR #1784 review, an improvement was identified in the check-params-env.sh
script's variable name extraction logic.
Current Behavior
The script currently uses a greedy sed pattern that matches everything up to the last =
character:
sed 's#\(.*\)=.*#\1#'
This could potentially cause issues if a variable name somehow contains an =
character (though unlikely in practice), as it would incorrectly include everything up to the last =
as part of the variable name.
Proposed Improvement
Use a non-greedy pattern that matches only up to the first =
character:
sed 's#^\([^=]*\)=.*#\1#'
Affected Files
ci/check-params-env.sh
(lines 55, 73)
Solution
Replace the greedy pattern with a non-greedy one in the check_variables_uniq
function:
Line 55 (checking variable uniqueness):
- content=$(sed '/^$/d' "${env_file_path_1}" "${env_file_path_2}" | sed 's#\(.*\)=.*#\1#' | sort)
+ content=$(sed '/^$/d' "${env_file_path_1}" "${env_file_path_2}" | sed 's#^\([^=]*\)=.*#\1#' | sort)
Line 73 (checking value uniqueness):
- content=$(sed '/^$/d' "${env_file_path_1}" "${env_file_path_2}" | sed 's#\(.*\)=.*#\1#' | sort)
+ content=$(sed '/^$/d' "${env_file_path_1}" "${env_file_path_2}" | sed 's#^\([^=]*\)=.*#\1#' | sort)
Benefits
- More robust parsing that correctly handles edge cases
- Follows best practices for parsing key-value pairs
- Prevents potential issues with variable names that might contain
=
characters
Acceptance Criteria
- Update sed pattern in
check_variables_uniq
function to use non-greedy matching - Test the script with various env file formats to ensure it still works correctly
- Verify no regression in existing functionality
Context
- PR: NO-JIRA: ensure empty lines are skipped while processing env files in
check-params-env.sh
#1784 - Comment: NO-JIRA: ensure empty lines are skipped while processing env files in
check-params-env.sh
#1784 (comment) - Requested by: @jiridanek
Additional Notes
This improvement was identified while implementing empty line handling in the same script. While the current greedy pattern likely works fine for typical environment files, using non-greedy matching is a more correct approach for parsing key-value pairs.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status