`set_key` does not handle single quote `'` inside value properly
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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()
- Ngôn ngữ chính
- Python
- Star
- 8.9k
- Fork
- 581
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của theskumar/python-dotenv
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
theskumar/python-dotenv#699 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
theskumar/python-dotenv#697 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
theskumar/python-dotenv#693 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
theskumar/python-dotenv#683 · 4 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
theskumar/python-dotenv#644 · 2 bình luận ·
Tất cả issue của theskumar/python-dotenv
Issue tương tự
-
[Bug] reef-hermes tells me to resume with hermes --resume, which does not work from my shell Đang mởarea: harness bug status: needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Human-Agent-Society/reef#625 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
learningequality/kolibri#15351 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Name consistency Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
eellak/triplestore#65 · 1 bình luận ·