`set_key` does not handle single quote `'` inside value properly
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 45/100
Direção de pesquisa
Start at the set_key entry point and reproduce the issue with the Python script in this report, then source the generated .env file in Bash. Trace how values are quoted and escaped, including the related PR discussion and warning about dotenv parsing. Done means a value containing a single quote is written in a form that both Bash can source and dotenv can parse correctly.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Problem
set_key function does not properly handle single quote ' inside value.
python-dotenv version: 1.0.1
Related PR
- https://github.com/theskumar/python-dotenv/pull/330 (https://github.com/theskumar/python-dotenv/pull/330#discussion_r669439596)
How to reproduce
- Run python script below
- Run
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 :(''
Example of fix
⚠️ this fix produces values that dotenv cannot parse (see this issue) ⚠️
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()
- Linguagem predominante
- Python
- Estrelas
- 8.9k
- Forks
- 612
- Merge médio
- 11h 19min
- PRs com merge (30d)
- 3
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de theskumar/python-dotenv
-
An empty value ignores ${name:-default}Talvez já em andamento @SashaMIT assumiu há 16 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
theskumar/python-dotenv#715 ·
Mantenedores costumam responder em até 1 dia
-
set_key and unset_key don't fsync before replacing the .env fileTalvez já em andamento @Imkkey assumiu há 16 dias. Abertaenhancement
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
theskumar/python-dotenv#713 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 28/100
theskumar/python-dotenv#693 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
python-dotenv installation without cli masks python-dotenv cliTalvez já em andamento @gyanu2507 assumiu há 55 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
theskumar/python-dotenv#683 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
-
Feature Request: Automatically copy `default.env` to `.env`Talvez já em andamento @dradetsky assumiu há 165 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
theskumar/python-dotenv#644 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de theskumar/python-dotenv
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 1 dia
-
infrastructure qa
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
khuisman/mcp-gee-sweet#1068 ·
Mantenedores costumam responder em até 1 dia
-
The book has a Nix install section that chelis.ch lacks, and it names two of the three systemsAbertaarea:ecosystem documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Chelis-Lang/chelis#3866 ·
Mantenedores costumam responder em até 1 dia
-
`lvm_compact` has no self-hosted twin, and `docs/158` §5 says every language-face component mustAbertabug sev-3 vm
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
issue: Picking a prompt from the / menu in a channel inserts a command chip instead of the promptAbertabug confirmed issue
Dificuldade 2/5 Meio dia Facilidade para iniciantes 78/100
open-webui/open-webui#32712 · 2 comentários ·
Mantenedores costumam responder em até 1 dia