Skip to content

set_key doesn't escape values with quotes in them #215

@soapergem

Description

@soapergem

Suppose you have this code:

import dotenv
import json

key = "KEY_TO_SAVE"
value = json.dumps({"test": "me"})
dotenv.set_key(".env", key, value)

What I would expect to see is a .env file that looks like this:

KEY_TO_SAVE="{\"test\": \"me\"}"

However what I actually see is this:

KEY_TO_SAVE="{"test": "me"}"

Because of the lack of escaping quote character, dotenv has effectively changed the value I was trying to set. In this case, the value passed to dotenv is valid JSON, but the value dotenv saves to the file is not valid JSON.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions