We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
set_key
'
set_key function does not properly handle single quote ' inside value.
python-dotenv version: 1.0.1
1.0.1
source .env
Python Script
from dotenv import set_key def main(): var_value = "I'm a bug :(" set_key(".env", "VAR", var_value) if __name__ == "__main__": main()
Error from source .env
bash: .env: line 1: syntax error near unexpected token `(' bash: .env: line 1: `VAR='I\'m a bug :(''
⚠️ this fix produces values that dotenv cannot parse (see this issue) ⚠️
dotenv
from dotenv import set_key def fixed_set_key(file_path, key, value): # properly escape ' if present # https://stackoverflow.com/questions/8254120/how-can-i-escape-a-single-quote-in-a-single-quote-string-in-bash/26165123#26165123 value = value.replace("'", "'\"'\"'") set_key(file_path, key, f"'{value}'", quote_mode="never") def main(): var_value = "I'm a fixed :)" fixed_set_key(".env", "VAR", var_value) if __name__ == "__main__": main()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Problem
set_key
function does not properly handle single quote'
inside value.python-dotenv version:
1.0.1
Related PR
set_key
#330 (Improve quoting of values inset_key
#330 (comment))How to reproduce
source .env
Python Script
Error from
source .env
Example of fix
dotenv
cannot parse (see this issue)The text was updated successfully, but these errors were encountered: