Skip to content

fix(cask): invalid string quoting in uninstall/zap arrays #5885

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

Merged
merged 2 commits into from
Jul 8, 2025

Conversation

stupside
Copy link
Contributor

@stupside stupside commented Jul 7, 2025

What this commit does

Fixes improper string quoting in Homebrew cask zap arrays to ensure valid Ruby syntax in generated cask files.

Previously, installing a cask with a zap stanza would result in an error due to unquoted strings.

Example configuration

GoReleaser config (valid YAML):

zap:
  trash:
    - "~/.moley/config.yml"

Generated cask (invalid Ruby):

zap trash: [
    ~/.moley/config.yml,
  ]

This results in a syntax error when running:

brew install --cask moley.rb

Error:

➜  mole git:(main) ✗ brew install --cask moley.rb
Warning: Cask 'moley' is unreadable: /Users/kilianhoupeurt/Documents/git/mole/mole/moley.rb:36: syntax errors found
  34 |
  35 |   zap trash: [
> 36 |       ~/.moley/config.yml,
     |               ^~~~~~~ unknown regexp options - cfg
  37 |     ],
  48 |

Actual fix

The fix updates the groupToS function to ensure all string values in the zap array are properly quoted using fmt.Sprintf("%q", l).

Correct output:

zap trash: [
    "~/.moley/config.yml",
  ]

With this fix, the cask installs correctly:

➜  mole git:(main) ✗ brew install --cask moley.rb
==> Downloading https://github.com/stupside/moley/releases/download/v1.1.2/moley_1.1.2_darwin_arm64.tar.gz
==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/1010395208/c4459
########################################################################################################### 100.0%
==> Installing Cask moley
==> Linking Binary 'moley' to '/opt/homebrew/bin/moley'
🍺  moley was successfully installed!

Why this change is necessary

Unquoted strings in Ruby array literals are treated as variables or invalid expressions, leading to syntax errors.

This change ensures:

  • All zap entries are quoted strings
  • Generated Ruby is syntactically valid
  • Casks using zap can be installed without manual intervention

Additional details

  • Consolidates quoting logic in groupToS
  • Updates test golden files accordingly

Fixes generation bug in Homebrew cask zap stanza

References:

stupside added 2 commits July 7, 2025 20:28
Update test expectations to reflect properly quoted strings in
uninstall and zap stanzas of generated Homebrew cask files.
Move string quoting from data collection phase to output generation
phase in groupToS function. This ensures proper quoting of launchctl,
quit, login_item, delete, and trash arrays in generated cask files.
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 7, 2025
@caarlos0 caarlos0 added the bug Something isn't working label Jul 8, 2025
Copy link
Member

@caarlos0 caarlos0 left a comment

Choose a reason for hiding this comment

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

ah, good catch! thanks!

Copy link

codecov bot commented Jul 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.68%. Comparing base (735ed6f) to head (625e81d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5885      +/-   ##
==========================================
- Coverage   82.68%   82.68%   -0.01%     
==========================================
  Files         165      165              
  Lines       16521    16520       -1     
==========================================
- Hits        13661    13660       -1     
  Misses       2268     2268              
  Partials      592      592              

☔ 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.

@caarlos0 caarlos0 merged commit 5d927a0 into goreleaser:main Jul 8, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants