fix(tekton): map last line git-instead-of#4844
Conversation
There was a problem hiding this comment.
I have already done a preliminary review for you, and I hope to help you do a better job.
Summary:
This PR fixes an issue in the Tekton git clone task where the last mapping in the PARAM_GIT_INSTEAD_OF parameter may be skipped due to how the shell while read loop processes input lines. The fix adds an additional condition to the loop to ensure the last line is processed even if it does not end with a newline. The change is minimal and focused, improving robustness of the git URL rewriting functionality.
Critical Issues:
- None found.
Code Improvements:
-
Shell Parsing Robustness (
tekton/v1/tasks/pingcap-git-clone.yamlline 260):- The addition of
|| [ -n "${mapping}" ]is a good fix to handle the last line without trailing newline. - However, the use of
echo -ncombined withtr ',' '\n'can fail ifPARAM_GIT_INSTEAD_OFcontains trailing commas or empty mappings. - Suggest trimming or sanitizing input before processing:
echo "${PARAM_GIT_INSTEAD_OF}" | tr ',' '\n' | sed '/^\s*$/d' | while IFS= read -r mapping || [ -n "$mapping" ]; do # ... done
- This removes empty lines caused by trailing commas and avoids unexpected empty mappings.
- The addition of
-
Parsing URL Mappings:
- The parsing uses
cut -d '=' -f 1andcut -d '>' -f 2. This assumes mappings in the formsomething=...>.... - Confirm and document the expected format of
PARAM_GIT_INSTEAD_OF. If the format issrc=dest, the use of>might be incorrect/confusing. - Clarify or add comments explaining the format and parsing logic to avoid future confusion.
- The parsing uses
Best Practices:
- Documentation:
- Add a comment above this block explaining what
PARAM_GIT_INSTEAD_OFis expected to contain and the purpose of this loop. - Example:
# Parse PARAM_GIT_INSTEAD_OF mappings of the form "src=dest" separated by commas, # and configure git url rewriting accordingly.
- Add a comment above this block explaining what
- Testing:
- If possible, add or update unit or integration tests covering edge cases such as:
- Single mapping without trailing newline
- Multiple mappings with trailing commas
- Empty or malformed mappings
- If possible, add or update unit or integration tests covering edge cases such as:
- Style:
- Prefer quoting variables inside the loop to avoid word splitting, e.g.:
is fine, but ensure
instead_of_url=$(echo "${mapping}" | cut -d '=' -f 1 | tr -d ' ' | tr -d '"')mappingis always quoted on reading and usage.
- Prefer quoting variables inside the loop to avoid word splitting, e.g.:
Summary: The fix correctly addresses the last line processing bug. Adding input sanitization, clarifying the mapping format, and improving documentation will make this more robust and maintainable.
|
/approve |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: timzxz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
No description provided.