Skip to content

hack: fix unquoted variables in hack scripts to prevent word-splitting#9018

Open
Ankitsinghsisodya wants to merge 5 commits intoknative:mainfrom
Ankitsinghsisodya:refactor/fix-quoting-hack-scripts
Open

hack: fix unquoted variables in hack scripts to prevent word-splitting#9018
Ankitsinghsisodya wants to merge 5 commits intoknative:mainfrom
Ankitsinghsisodya:refactor/fix-quoting-hack-scripts

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

Combines #8990, #8992, and #9004 into a single PR as requested by @creydr.

Also fixes main $@main "$@" in release.sh spotted during review.

Changes

  • generate-yamls.sh: Quote ${YAML_OUTPUT_DIR} in rm command
  • release.sh: Quote $(dirname $0) invocation, ${REPO_ROOT_DIR} in cp, and $@ in main call
  • verify-codegen.sh: Quote ${REPO_ROOT_DIR} inside mktemp call

Unquoted variable expansions and command substitutions break when paths contain whitespace.

Closes #8990
Closes #8992
Closes #9004

- generate-yamls.sh: quote YAML_OUTPUT_DIR in rm command
- release.sh: quote dirname substitution, REPO_ROOT_DIR in cp, and $@
- verify-codegen.sh: quote REPO_ROOT_DIR inside mktemp call

Unquoted variable expansions and command substitutions break when paths
contain whitespace.

Closes knative#8990
Closes knative#8992
Closes knative#9004
Copilot AI review requested due to automatic review settings April 14, 2026 18:06
@knative-prow knative-prow bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 14, 2026
@knative-prow knative-prow bot requested review from creydr and evankanderson April 14, 2026 18:07
@knative-prow knative-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 14, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 14, 2026

Hi @Ankitsinghsisodya. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens several hack/ bash scripts by quoting variable expansions/command substitutions to prevent word-splitting when paths contain whitespace, combining the changes from #8990, #8992, and #9004.

Changes:

  • Quote ${YAML_OUTPUT_DIR} in hack/generate-yamls.sh when removing generated YAMLs.
  • Quote $(dirname ...) usage, ${REPO_ROOT_DIR} copy destination, and main "$@" invocation in hack/release.sh.
  • Quote ${REPO_ROOT_DIR} in the mktemp template path in hack/verify-codegen.sh.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
hack/verify-codegen.sh Quotes the mktemp directory template to handle repo paths with spaces.
hack/release.sh Quotes script path resolution, repo-root copy destination, and "$@" propagation (but see review comment about cp).
hack/generate-yamls.sh Quotes the output directory in rm while preserving glob expansion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hack/release.sh Outdated
Comment on lines 69 to 73
ARTIFACTS_TO_PUBLISH=$(cat "${YAML_LIST}" | tr '\n' ' ')
if (( ! PUBLISH_RELEASE )); then
# Copy the generated YAML files to the repo root dir if not publishing.
cp ${ARTIFACTS_TO_PUBLISH} ${REPO_ROOT_DIR}
cp "${ARTIFACTS_TO_PUBLISH}" "${REPO_ROOT_DIR}"
fi
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoting "${ARTIFACTS_TO_PUBLISH}" breaks cp when it contains multiple YAML paths (it becomes a single argument like "file1.yaml file2.yaml ..." and cp will fail). To preserve whitespace-safe paths and multiple files, read the YAML list into an array (e.g., mapfile -t artifacts < "${YAML_LIST}") and then cp "${artifacts[@]}" "${REPO_ROOT_DIR}" (or otherwise iterate line-by-line) instead of building a space-delimited string.

Copilot uses AI. Check for mistakes.
@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor Author

@creydr I have raised a seperate PRs and closed those three PRs as suggested by you.

Using a quoted space-delimited string with cp treats all paths as a
single argument and breaks with multiple files. Read YAML_LIST into a
local array with mapfile for the cp call, while keeping ARTIFACTS_TO_PUBLISH
as a space-separated string that the upstream knative/hack release.sh
expects.
Copy link
Copy Markdown
Member

@creydr creydr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ankitsinghsisodya for combining them. I left one question

Comment thread hack/release.sh
Comment on lines +68 to +73
"$(dirname "$0")/generate-yamls.sh" "${REPO_ROOT_DIR}" "${YAML_LIST}"
mapfile -t artifacts < "${YAML_LIST}"
ARTIFACTS_TO_PUBLISH="${artifacts[*]}"
if (( ! PUBLISH_RELEASE )); then
# Copy the generated YAML files to the repo root dir if not publishing.
cp ${ARTIFACTS_TO_PUBLISH} ${REPO_ROOT_DIR}
cp "${artifacts[@]}" "${REPO_ROOT_DIR}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Copy Markdown
Contributor Author

@Ankitsinghsisodya Ankitsinghsisodya Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@creydr The original cp ${ARTIFACTS_TO_PUBLISH} ${REPO_ROOT_DIR} had two issues:

  1. Word splitting on $ARTIFACTS_TO_PUBLISH — that variable holds space-separated filenames. If any filename contains spaces or glob characters, the shell splits it incorrectly before passing it to cp. Using "${artifacts[@]}" (a bash array) passes each element as a distinct argument, safely.

  2. RedundancyARTIFACTS_TO_PUBLISH="${artifacts[*]}" (line 70) collapses the array back into a single space-joined string. The new code skips that intermediary and goes straight from the array to cp, which is both simpler and correct.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ARTIFACTS_TO_PUBLISH needed then? Or you rename artifacts to ARTIFACTS_TO_PUBLISH to make it a bit clearer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have Remove it. it was dead code after switching to cp
"${artifacts[@]}". The array flows directly into cp now with no intermediate
variable needed.

@creydr
Copy link
Copy Markdown
Member

creydr commented Apr 15, 2026

/ok-to-test

@knative-prow knative-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 15, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 15, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ankitsinghsisodya
Once this PR has been reviewed and has the lgtm label, please assign cardil for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.07%. Comparing base (c6be563) to head (fb8046c).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9018      +/-   ##
==========================================
+ Coverage   51.02%   51.07%   +0.05%     
==========================================
  Files         409      409              
  Lines       22001    21996       -5     
==========================================
+ Hits        11225    11234       +9     
+ Misses       9914     9899      -15     
- Partials      862      863       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/test-and-release Test infrastructure, tests or release ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants