Repository navigation
Stop escaping # before {, $ and @ in shell values - #1986
Open
Harsh23Kashyap wants to merge 4 commits into
Open
Harsh23Kashyap wants to merge 4 commits into
Harsh23Kashyap wants to merge 4 commits into
Conversation
Copilot stopped reviewing on behalf of
Harsh23Kashyap due to an error
November 8, 2026 09:15
Contributor
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
2 open issues
What changed in this PR
This PR adjusts Kamal::Utils.escape_shell_value to avoid leaving an extra backslash before # sequences (#{, #$, #@) introduced by String#dump, and adds regression tests to ensure correct escaping and safe shell round-tripping.
Changes:
- Add a regex to undo
String#dump’s escaping of#before{,$, or@while preserving preceding escaped backslashes. - Extend
escape_ascii_shell_valuewith agsubpass to apply that correction. - Add unit tests for the new escaping behavior plus a shell round-trip test.
| File | Description |
|---|---|
test/utils_test.rb |
Adds regression and round-trip tests covering # + interpolation-like sequences. |
lib/kamal/utils.rb |
Introduces DUMP_ESCAPED_INTERPOLATION_HASH_REGEX and applies it in escape_ascii_shell_value. |
Review effort: Lite
Use Open3.capture3 to check shell success as well as the output. Skip only when /bin/sh is absent.
Author
|
Addressed both review points in 0dd0b36 and a80af54. The round-trip test now calls /bin/sh explicitly through Open3.capture3, checks the exit status and output, and skips when /bin/sh is absent. The regex comment includes a concrete before/after example. No production behavior changed in this follow-up. Checked on Ruby 3.4.7:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


escape_ascii_shell_valuebuilds its result withString#dump, which writes#as\#when it comes right before{,$or@. Inside double quotes the shell keeps that backslash, so a builder arg likeMSG='a#{b}'reaches docker asa\#{b}. #1114 fixed the same thing for env files, but this shell path was left alone.The fix removes that
\#escape right afterdump, before the backtick and dollar handling, and leaves an escaped backslash followed by a literal#alone. It is a small regex inlib/kamal/utils.rb.How I checked it:
test/utils_test.rb: one on the exact string, one that round trips values throughprintf. Both fail on main (2 failures) and pass with the change.sh: 173 came back different on main, 0 with the change.