Repository: theskumar/python-dotenv

Issue:
Wrong parsing of env variables in single quotes
I have the following `.env` file:
```
DATABASE_URL='postgres://localhost:5432/myapp_development'
```

When I run `dotenv get DATABASE_URL` this is what I get:
`DATABASE_URL="'postgres://localhost:5432/simulator_development'"`

When I try to use this with [dj-database-url](https://github.com/kennethreitz/dj-database-url) it is failing to parse the `DATABASE_URL` environment variable as it is.
It seems using single quotes in the `.env` file is causing this. 

It would be nice if this were documented somewhere if the behavior is intended 
I spent quite a bit of time trying to figure out where the error was.
Thanks 😃


Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/10844638/badge)](https://coveralls.io/builds/10844638)

Coverage remained the same at 82.418% when pulling **a2096aa6fc7425ed5c8d9280cc3acd05a6fa5eab on Flimm:naive-single-quotes** into **9552db8d8c25753ec4f1a724f64d895b9daa6296 on theskumar:master**.

theskumar: @Flimm At the first look it does not seem to fix the issue where parser keeps the `'` quote around the value when reading the `.env` file. thoughts?
Flimm: Sorry, you're right, I forgot to push a third commit. 😳  Have a look now.
coveralls: 
[![Coverage Status](https://coveralls.io/builds/10845005/badge)](https://coveralls.io/builds/10845005)

Coverage remained the same at 82.418% when pulling **9b5582ea85c99f704bce9012c2741d28b46981ed on Flimm:naive-single-quotes** into **9552db8d8c25753ec4f1a724f64d895b9daa6296 on theskumar:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/10845005/badge)](https://coveralls.io/builds/10845005)

Coverage remained the same at 82.418% when pulling **9b5582ea85c99f704bce9012c2741d28b46981ed on Flimm:naive-single-quotes** into **9552db8d8c25753ec4f1a724f64d895b9daa6296 on theskumar:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/10845005/badge)](https://coveralls.io/builds/10845005)

Coverage remained the same at 82.418% when pulling **9b5582ea85c99f704bce9012c2741d28b46981ed on Flimm:naive-single-quotes** into **9552db8d8c25753ec4f1a724f64d895b9daa6296 on theskumar:master**.

theskumar: This is looks pretty good. Love the tests 😍 !

Patch:
diff --git a/README.rst b/README.rst
index 936a5a2..8b2a039 100644
--- a/README.rst
+++ b/README.rst
@@ -126,7 +126,8 @@ update your settings on remote server, handy isn't it!
                                       file in current working directory.
       -q, --quote [always|never|auto]
                                       Whether to quote or not the variable values.
-                                      Default mode is always.
+                                      Default mode is always. This does not affect
+                                      parsing.
       --help                          Show this message and exit.
 
     Commands:
diff --git a/dotenv/cli.py b/dotenv/cli.py
index 9a99314..125a0a8 100644
--- a/dotenv/cli.py
+++ b/dotenv/cli.py
@@ -11,7 +11,7 @@ from .main import get_key, dotenv_values, set_key, unset_key
               help="Location of the .env file, defaults to .env file in current working directory.")
 @click.option('-q', '--quote', default='always',
               type=click.Choice(['always', 'never', 'auto']),
-              help="Whether to quote or not the variable values. Default mode is always.")
+              help="Whether to quote or not the variable values. Default mode is always. This does not affect parsing.")
 @click.pass_context
 def cli(ctx, file, quote):
     '''This script is used to set, get or unset values from a .env file.'''
diff --git a/dotenv/main.py b/dotenv/main.py
index 2fe1a83..ceac3fa 100644
--- a/dotenv/main.py
+++ b/dotenv/main.py
@@ -103,7 +103,7 @@ def parse_dotenv(dotenv_path):
             k, v = k.strip(), v.strip()
 
             if len(v) > 0:
-                quoted = v[0] == v[len(v) - 1] == '"'
+                quoted = v[0] == v[len(v) - 1] in ['"', "'"]
 
                 if quoted:
                     v = decode_escaped(v[1:-1])


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index d78172b..449b54a 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -46,6 +46,18 @@ def test_key_value_without_quotes():
     sh.rm(dotenv_path)
 
 
+def test_value_with_quotes():
+    with open(dotenv_path, 'w') as f:
+        f.write('TEST="two words"\n')
+    assert dotenv.get_key(dotenv_path, 'TEST') == 'two words'
+    sh.rm(dotenv_path)
+
+    with open(dotenv_path, 'w') as f:
+        f.write("TEST='two words'\n")
+    assert dotenv.get_key(dotenv_path, 'TEST') == 'two words'
+    sh.rm(dotenv_path)
+
+
 def test_unset():
     sh.touch(dotenv_path)
     success, key_to_set, value_to_set = dotenv.set_key(dotenv_path, 'HELLO', 'WORLD')
@@ -104,6 +116,13 @@ def test_get_key_with_interpolation(cli):
         dotenv.set_key(dotenv_path, 'FOO', '${HELLO}')
         dotenv.set_key(dotenv_path, 'BAR', 'CONCATENATED_${HELLO}_POSIX_VAR')
 
+        lines = list(open(dotenv_path, "r").readlines())
+        assert lines == [
+            'HELLO="WORLD"\n',
+            'FOO="${HELLO}"\n',
+            'BAR="CONCATENATED_${HELLO}_POSIX_VAR"\n',
+        ]
+
         # test replace from variable in file
         stored_value = dotenv.get_key(dotenv_path, 'FOO')
         assert stored_value == 'WORLD'