Skip to content
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

Handle parentheses in variables in commands #525

Closed
wants to merge 1 commit into from

Conversation

i7an
Copy link

@i7an i7an commented Jan 6, 2025

Variables with parentheses are not handled correctly in commands:

FOO='passwo(rd'
BAR=$(echo '$FOO')

Result:

expected: {"BAR"=>"passwo(rd",           "FOO"=>"passwo(rd"}
     got: {"BAR"=>"$(echo 'passwo(rd')", "FOO"=>"passwo(rd"}

The solution I suggest is to parse commands first and expand variables before executing commands.

@@ -8,11 +8,6 @@ class FormatError < SyntaxError; end
# Parses the `.env` file format into key/value pairs.
# It allows for variable substitutions, command substitutions, and exporting of variables.
class Parser
@substitutions = [
Copy link
Author

@i7an i7an Jan 6, 2025

Choose a reason for hiding this comment

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

I think this is effectively private API. But kamal relies on it, which does not sound right to me. Please consider this.

I'll submit a patch to Kamal if this PR is ok.

Should I keep substitutions and call Variable from Command to reduce the chance of breaking something? 🤔

# lib/dotenv/substitutions/command.rb
def call(value, &block)
  # ...
  `#{Variable.call(command, env) }`.chomp
  # ...
end

@i7an i7an closed this Jan 7, 2025
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.

1 participant