Skip to content

Fix caveats replacing order (HOMEBREW_PREFIX) in API formula reconstruction#22810

Open
umireon wants to merge 2 commits into
Homebrew:mainfrom
umireon:umireon/fix-var-path
Open

Fix caveats replacing order (HOMEBREW_PREFIX) in API formula reconstruction#22810
umireon wants to merge 2 commits into
Homebrew:mainfrom
umireon:umireon/fix-var-path

Conversation

@umireon

@umireon umireon commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

$HOMEBREW_PREFIX prefiexed with / (e.g. unix://$HOMEBREW_PREFIX) results in broken path.
This is because /$HOME is replaced before $HOMEBREW_PREFIX in API.
This PR fixes the order of replacing HOMEBREW_PREFIX, HOMEBREW_CELLAR, HOME.

Actual behavior

% brew info socktainer
==> socktainer ✔: stable 1.0.0 (bottled), HEAD
Docker-compatible REST API on top of Apple container
https://socktainer.github.io
Installed (on request)
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/s/socktainer.rb
License: Apache-2.0
==> Installed Kegs and Versions
socktainer ✔ HEAD-21af0b5 (7 files, 68.6MB) [Linked]
==> Dependencies
Required (1): container ✔
Recursive Runtime (1): all installed ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
Socktainer exposes a Docker-compatible REST API. You can connect any tools you installed for Docker daemon.

To connect it to your tools, add the following to ~/.bash_profile or ~/.zshrc:
  export DOCKER_HOST=unix://Users/umireonBREW_PREFIX/var/run/socktainer/.socktainer/container.sock

To restart socktainer after an upgrade:
  brew services restart socktainer
Or, if you don't want/need a background service you can just run:
  HOME="/opt/homebrew/var/run/socktainer" /opt/homebrew/opt/socktainer/bin/socktainer
==> Analytics
install: 14 (30 days), 29 (90 days), 29 (365 days)
install-on-request: 14 (30 days), 29 (90 days), 29 (365 days)
build-error: 0 (30 days)

Expected behavior

To connect it to your tools, add the following to ~/.bash_profile or ~/.zshrc:
  export DOCKER_HOST=unix:///opt/homebrew/var/run/socktainer/.socktainer/container.sock

  • 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 Hyperfine benchmarks.
  • 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?

  • AI was used to generate or assist with generating this PR.

I used OpenAI Codex to investigate the root cause of this bug. I wrote all the code by my hands and carefully examined thoroughly. I have run test and actual command repeatedly to confirm this change works as expected.


$HOMEBREW_PREFIX prefiexed with / (e.g. unix://$HOMEBREW_PREFIX) results in broken path.
This is because `/$HOME` is replaced before `$HOMEBREW_PREFIX` in API.

Signed-off-by: Kaito Udagawa <umireon@kaito.tokyo>
@umireon

umireon commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Waiting for initial test case failure

Use the same order as formulary.rb.

Signed-off-by: Kaito Udagawa <umireon@kaito.tokyo>
@umireon

umireon commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Test passed. I'm confident with this PR to fix the bug.

@umireon umireon marked this pull request as ready for review June 19, 2026 09:26
Copilot AI review requested due to automatic review settings June 19, 2026 09:26

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.

Pull request overview

This PR fixes a placeholder-replacement ordering issue when reconstructing Formula data from the API, preventing $HOMEBREW_PREFIX (and $HOMEBREW_CELLAR) from being partially rewritten by the /$HOME placeholder replacement in strings like unix://$HOMEBREW_PREFIX.

Changes:

  • Reorder placeholder substitutions in APIHashable#deep_remove_placeholders to replace prefix/cellar before home.
  • Add an RSpec regression test ensuring unix://$HOMEBREW_PREFIX is reconstructed correctly in FormulaStruct.from_hash.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Library/Homebrew/api_hashable.rb Fixes placeholder replacement order to avoid /$HOME matching inside /$HOMEBREW_PREFIX//$HOMEBREW_CELLAR.
Library/Homebrew/test/api/formula_struct_spec.rb Adds a regression test covering the previously broken unix://$HOMEBREW_PREFIX caveats reconstruction case.

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

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.

2 participants