Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

`set_key` does not handle single quote `'` inside value properly

Offen
#543 1 Kommentar 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@SAY-5 arbeitet bereits daran.

Seit 13.5.2026.

  • #647 von @SAY-5 — offen
  • #670 von @j0m0k0 — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python
Bereich
tooling

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Problem

set_key function does not properly handle single quote ' inside value.

python-dotenv version: 1.0.1

Related PR

How to reproduce

  1. Run python script below
  2. 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()
Vorherrschende Sprache
Python
Sterne
8.9k
Forks
600
Ø Merge
4 T. 23 Std.
Gemergte PRs (30 T.)
4

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus theskumar/python-dotenv

Alle Issues in theskumar/python-dotenv

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.