Skip to content

t4944: Use printf %q for wp_args logging to handle spaces#4950

Closed
alex-solovyev wants to merge 2 commits intomainfrom
bugfix/t4944-wp-args-logging
Closed

t4944: Use printf %q for wp_args logging to handle spaces#4950
alex-solovyev wants to merge 2 commits intomainfrom
bugfix/t4944-wp-args-logging

Conversation

@alex-solovyev
Copy link
Collaborator

@alex-solovyev alex-solovyev commented Mar 15, 2026

Summary

  • Replaces ${wp_args[*]} with $(printf '%q ' "${wp_args[@]}") in wp-helper.sh:383 so arguments containing spaces are logged with proper quoting, making debug output accurate and unambiguous.

Closes #4944

Summary by CodeRabbit

  • Chores
    • Improved logging safety in internal helper scripts to safely preserve command arguments without shell expansion, enhancing audit trail accuracy and preventing issues with special characters.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the debugging experience for WP-CLI commands by ensuring that arguments, especially those containing spaces, are logged with proper shell quoting. This change makes the logged commands directly usable and prevents misinterpretation of complex arguments during troubleshooting, leading to more accurate and unambiguous debug output.

Highlights

  • Improved WP-CLI Argument Logging: Modified wp-helper.sh to use printf '%q ' for logging wp_args, ensuring that arguments containing spaces are correctly quoted and debug output is accurate and unambiguous.
Changelog
  • .agents/scripts/wp-helper.sh
    • Updated the logging of WP-CLI arguments to correctly handle spaces by using printf %q.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

Warning

Rate limit exceeded

@alex-solovyev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b434d078-5475-43b9-90de-ae413eb2e45b

📥 Commits

Reviewing files that changed from the base of the PR and between 6271718 and 28edbd8.

📒 Files selected for processing (1)
  • .agents/scripts/wp-helper.sh

Walkthrough

Updated log message formatting in .agents/scripts/wp-helper.sh to quote WP-CLI arguments using printf '%q ' for proper display, addressing review feedback about argument readability in logs. Execution behavior unchanged.

Changes

Cohort / File(s) Summary
WP-CLI Argument Logging
.agents/scripts/wp-helper.sh
Modified run_wp_command log message to safely quote arguments using printf '%q ' instead of unquoted variable expansion, improving log clarity for arguments containing spaces.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

📝 A log message now rings clear and true,
Arguments quoted, nothing misconstrued,
Spaces preserved, the debug path shines,
Shell script polish—quality refined! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing unquoted wp_args with printf %q formatting to handle spaces in logging.
Linked Issues check ✅ Passed The PR implements the exact solution specified in issue #4944: replacing ${wp_args[*]} with $(printf '%q ' "${wp_args[@]}") to properly quote arguments containing spaces in logs.
Out of Scope Changes check ✅ Passed Changes are limited to the logging statement in wp-helper.sh as specified in issue #4944; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/t4944-wp-args-logging
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 362 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Mar 15 18:43:36 UTC 2026: Code review monitoring started
Sun Mar 15 18:43:36 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 362

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 362
  • VULNERABILITIES: 0

Generated on: Sun Mar 15 18:43:39 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request correctly addresses an issue with logging command arguments that contain spaces by using printf %q. This makes the debug output unambiguous. I've suggested a small improvement to remove a trailing space from the log output for better formatting and efficiency, aligning with the practice of using pure Bash parameter expansion for string manipulations to avoid subshells.

site_type=$(echo "$site_config" | jq -r '.type')

print_info "Running on $site_name ($site_type): wp ${wp_args[*]}" >&2
print_info "Running on $site_name ($site_type): wp $(printf '%q ' "${wp_args[@]}")" >&2

Choose a reason for hiding this comment

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

medium

While using printf '%q ' is a great way to handle arguments with spaces, it introduces a trailing space in the log message. To produce a cleaner log output without the trailing space, you could store the result in a variable and then use shell parameter expansion to trim the last character. This is also slightly more efficient as it avoids forking an external process like sed.

Suggested change
print_info "Running on $site_name ($site_type): wp $(printf '%q ' "${wp_args[@]}")" >&2
local args_str
args_str=$(printf '%q ' "${wp_args[@]}")
print_info "Running on $site_name ($site_type): wp ${args_str% }" >&2
References
  1. In shell scripts, use pure Bash parameter expansion for string manipulations to avoid spawning subshells and improve performance.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
.agents/scripts/wp-helper.sh (2)

447-447: Same pattern needs updating in run_on_all.

This is the third location using ${wp_args[*]} for logging. Apply the same fix for consistency with line 383:

♻️ Proposed fix
-	print_info "Command: wp ${wp_args[*]}"
+	print_info "Command: wp $(printf '%q ' "${wp_args[@]}")"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/scripts/wp-helper.sh at line 447, In run_on_all update the logging
to use the array-safe expansion: replace the print_info call that currently uses
${wp_args[*]} with the quoted array form "${wp_args[@]}" so individual wp_args
elements are preserved; specifically change the print_info invocation that
references wp_args to use "${wp_args[@]}" (symbols: run_on_all, wp_args,
print_info).

404-404: Same ambiguity issue exists here—apply consistent fix.

This line still uses ${wp_args[*]}, which flattens arguments with spaces into ambiguous output (the exact issue this PR addresses at line 383). For consistent, unambiguous logging across all functions:

♻️ Proposed fix
-	print_info "Command: wp ${wp_args[*]}"
+	print_info "Command: wp $(printf '%q ' "${wp_args[@]}")"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/scripts/wp-helper.sh at line 404, The log uses the ambiguous
expansion "${wp_args[*]}"; change logging to produce an unambiguous, safely
quoted representation of the arguments instead of using wp_args[*]. For example,
build a quoted string from the array with printf '%q ' on "${wp_args[@]}" (or an
equivalent loop) and pass that result to print_info (replace the print_info call
that references wp_args[*] to use the safe_quoted variable), so use
"${wp_args[@]}" with quoting via printf '%q' to preserve argument boundaries and
spaces.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.agents/scripts/wp-helper.sh:
- Line 447: In run_on_all update the logging to use the array-safe expansion:
replace the print_info call that currently uses ${wp_args[*]} with the quoted
array form "${wp_args[@]}" so individual wp_args elements are preserved;
specifically change the print_info invocation that references wp_args to use
"${wp_args[@]}" (symbols: run_on_all, wp_args, print_info).
- Line 404: The log uses the ambiguous expansion "${wp_args[*]}"; change logging
to produce an unambiguous, safely quoted representation of the arguments instead
of using wp_args[*]. For example, build a quoted string from the array with
printf '%q ' on "${wp_args[@]}" (or an equivalent loop) and pass that result to
print_info (replace the print_info call that references wp_args[*] to use the
safe_quoted variable), so use "${wp_args[@]}" with quoting via printf '%q' to
preserve argument boundaries and spaces.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 524added-3ce7-4abb-9b93-01a9b4c5a871

📥 Commits

Reviewing files that changed from the base of the PR and between cd6ca4c and 6271718.

📒 Files selected for processing (1)
  • .agents/scripts/wp-helper.sh

…lper.sh

Address SonarCloud Maintainability C rating by extracting inline command
substitution to a local variable. Apply the same safe-quoting pattern to
all three wp_args logging sites (run_wp_command, run_on_category,
run_on_all) for consistency. Trim trailing space from printf '%q ' output
using parameter expansion per Gemini review suggestion.
@marcusquinn
Copy link
Owner

Dispatching worker to address review suggestions.

  • Model: sonnet (anthropic/claude-sonnet-4-6)
  • Branch: fix/t4944-review-suggestions
  • Scope: Apply Gemini suggestion: use ${args_str% } to trim trailing space in wp-helper.sh log line
  • Attempt: 1 of 1
  • Direction: Pure shell parameter expansion, no subshell fork

@github-actions
Copy link
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 362 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Mar 15 18:51:06 UTC 2026: Code review monitoring started
Sun Mar 15 18:51:06 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 362

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 362
  • VULNERABILITIES: 0

Generated on: Sun Mar 15 18:51:08 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

marcusquinn added a commit that referenced this pull request Mar 15, 2026
Replace subshell-in-string $(printf '%q ' ...) with a two-step pattern:
  local args_str; args_str=$(printf '%q ' "${wp_args[@]}")
  ... ${args_str% }

This avoids spawning an extra subshell inside the double-quoted string and
uses pure shell parameter expansion (${args_str% }) to strip the trailing
space left by printf '%q '. Applied to all three logging sites:
run_wp_command (line 383), run_on_category (line 404), run_on_all (line 447).

Addresses Gemini Code Assist suggestion on PR #4950.
@marcusquinn
Copy link
Owner

Addressed the Gemini Code Assist suggestion in PR #4953.

Change: Replaced the subshell-in-string pattern $(printf '%q ' "${wp_args[@]}") with shell parameter expansion ${args_str% } to trim the trailing space — no extra subshell fork needed.

Also extended the fix to the two remaining ${wp_args[*]} logging sites in run_on_category and run_on_all that were flagged by CodeRabbit.

Branch: fix/t4944-review-suggestions

marcusquinn added a commit that referenced this pull request Mar 15, 2026
…in wp_args log (#4953)

* fix: use printf '%q' for wp_args logging to handle spaces in arguments

Closes #4944

* fix: use shell parameter expansion to trim trailing space in wp_args log

Replace subshell-in-string $(printf '%q ' ...) with a two-step pattern:
  local args_str; args_str=$(printf '%q ' "${wp_args[@]}")
  ... ${args_str% }

This avoids spawning an extra subshell inside the double-quoted string and
uses pure shell parameter expansion (${args_str% }) to strip the trailing
space left by printf '%q '. Applied to all three logging sites:
run_wp_command (line 383), run_on_category (line 404), run_on_all (line 447).

Addresses Gemini Code Assist suggestion on PR #4950.

---------

Co-authored-by: Alexey <1556417+alex-solovyev@users.noreply.github.com>
@marcusquinn
Copy link
Owner

Superseded by PR #4953 which addresses the Gemini Code Assist review suggestion (trailing space fix using shell parameter expansion). Closing this original PR.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quality-debt: .agents/scripts/wp-helper.sh — PR #4938 review feedback (medium)

2 participants