Skip to content

shell: fish-quote the fish profile line - #24114

Merged
MikeMcQuaid merged 2 commits into
Homebrew:mainfrom
rawsun007:shell-fish-profile-quote
Sep 29, 2026
Merged

MikeMcQuaid merged 2 commits into
Homebrew:mainfrom
rawsun007:shell-fish-profile-quote

Conversation

@rawsun007

Copy link
Copy Markdown
Contributor

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Follow-up to #24042, which wrapped every profile line in sh_single_quote. The line is run by the user's own shell, and for fish that is wrong: inside fish single quotes \' and \\ are escapes, so '\'' never closes the string.

$ fish -c "$(brew ruby -e 'require "utils/shell"; ENV["SHELL"]="fish"; puts Utils::Shell.set_variable_in_profile("X", "a'\''b")')"
fish: Unexpected end of string, quotes are not balanced

A backslash is also lost silently: back\slash is written as backslash.

This adds fish_quote and uses it for the fish echo. Running each generated command in fish and sourcing the result in fish, 18 values including quotes, backslashes, $, backticks and spaces: main gets 3 wrong, this gets none wrong. prepend_path_in_profile uses fish_add_path with sh_quote, which fish reads correctly, so it is unchanged. Reverting the call site fails exactly the new test.

AI disclosure: written with Claude Code (Claude Opus 5.5) on my account. I reviewed the diff and will answer review comments myself.

Inside fish single quotes \' and \\ are escapes, so the POSIX '\''
sequence from sh_single_quote left the string unterminated.
Copilot AI lite review requested due to automatic review settings September 29, 2026 06:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Add regression coverage for backslash escaping.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates Fish profile command generation to preserve quotes and backslashes safely.

Changes:

  • Adds Fish-specific quoting.
  • Applies it to Fish profile assignments.
  • Adds apostrophe regression coverage.

Review feedback requests a regression test covering backslashes.

File Summary
Library/​Homebrew/​utils/​shell.rb Implements and applies Fish-compatible quoting.
Library/​Homebrew/​test/​utils/​shell_spec.rb Tests apostrophe handling; backslash coverage remains needed.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@MikeMcQuaid MikeMcQuaid left a comment

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.

Thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Sep 29, 2026
Merged via the queue into Homebrew:main with commit ddb313b Sep 29, 2026
51 checks passed
MikeMcQuaid added a commit to rawsun007/brew that referenced this pull request Oct 3, 2026
- Revert speculative quoting from Homebrew#24035, Homebrew#24042, Homebrew#24105, Homebrew#24114
  and Homebrew#24154 after the author confirmed it lacked user reports.
- Revert Homebrew#24053 and Homebrew#24144: repeated singleton headers and rounding
  boundaries have no reported user failures in their discussions.
- Use `Shellwords.escape` and `Process.spawn` instead of maintaining
  duplicate escaping and process setup logic.
- Preserve tilde expansion and csh newline quoting, and reuse the
  profile map as the supported-shell list.
- Inline redirect resolution and headline formatting into their
  sole callers; exercise redirects through the download strategy.
- Retain ordinary PowerShell and mksh fixes, archive validation and
  runtime migrations that avoid duplicating existing functionality.
MikeMcQuaid added a commit to rawsun007/brew that referenced this pull request Oct 3, 2026
- Revert speculative quoting from Homebrew#24035, Homebrew#24042, Homebrew#24105, Homebrew#24114
  and Homebrew#24154 after the author confirmed it lacked user reports.
- Use `Shellwords.escape` and `Process.spawn` instead of maintaining
  duplicate escaping and process setup logic.
- Preserve tilde expansion and convert Ruby's quoted newlines for
  csh without changing the backslashes already escaped by Ruby.
- Reuse the profile map as the supported-shell list and inline
  single-use locals while retaining ordinary PowerShell support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

⌂ 换网址