`set_key` does not handle single quote `'` inside value properly
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 45/100
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
- 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()
- Vorherrschende Sprache
- Python
- Sterne
- 8.9k
- Forks
- 600
- Ø Merge
- 4 T. 23 Std.
- Gemergte PRs (30 T.)
- 4
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus theskumar/python-dotenv
-
An empty value ignores ${name:-default}Evtl. vergeben @SashaMIT hat das vor 8 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
theskumar/python-dotenv#715 ·
Maintainer antworten meist innerhalb von 1 Tag
-
set_key and unset_key don't fsync before replacing the .env fileEvtl. vergeben @Imkkey hat das vor 8 Tagen übernommen. Offenenhancement
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
theskumar/python-dotenv#713 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 28/100
theskumar/python-dotenv#693 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
python-dotenv installation without cli masks python-dotenv cliEvtl. vergeben @gyanu2507 hat das vor 47 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
theskumar/python-dotenv#683 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Feature Request: Automatically copy `default.env` to `.env`Evtl. vergeben @dradetsky hat das vor 157 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
theskumar/python-dotenv#644 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in theskumar/python-dotenv
Ähnliche Issues
-
Performance: deprecated DeviceEntry.config_entries access blocks the event loop for tens of secondsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
tuya/tuya_cloud_ha_bridge#14 ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
semantica-agi/semantica#1968 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
-
agent: ready area: submission priority: high type: docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
dkritarth/scopewatch#213 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Broken link in RELEASE.mdEvtl. vergeben @Jah-yee hat das heute übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
sphinx-contrib/httpdomain#143 ·
Maintainer antworten meist innerhalb von 1 Tag