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

Coverage decreased (-1.07%) to 89.286% when pulling **34d5fe41a9fa05f6f2fd306b728483c880222ae9 on bbc2:fix-unquoted-double-space** into **6ca2e2ab399c7e41be276bc830f21af3092f5d28 on theskumar:master**.

x-yuri: I was reverse-engineering the parsing rules. So I thought, maybe the documentation can be improved in this PR? Here's what I've managed to find out:

> Keys can be unquoted, and single-quoted. Values can be unquoted, single- and double-quoted. Spaces before and after keys, equal signs, and values are ignored. Values can be followed by a comment.
> 
> Allowed escape sequences in single-quoted values are: `\\`, `\'`. \
In double-quoted ones: `\\`, `\'`, `\"`, `\a`, `\b`, `\f`, `\n`, `\r`, `\t`, `\v`.

bbc2: Your reverse-engineering looks correct to me.  However, if we're going to describe quoting, there are many other features that we should also describe, like variable interpolation, so I'd rather not do it right now.

> On yet another hand, env files parsers are incompatible as it is.

Yes.  Before I fully refactored the parser months ago, I had a look at popular parsers for other languages and it's a mess.  You can see some of that mess at https://bbc2.github.io/dotenv-parser-comparisons/.

> And well, people might be doing it as we speak :)

Indeed they are.  It's common to see new GitHub issues created right after a subtle parsing change was made.  I've tried to be careful about breaking changes but sometimes you really need them (e.g. when you're the only parser in the world with some weird behavior).
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 34cdb32..b5305f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,8 +19,10 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ### Fixed
 
-- Fix potentially empty expanded value for duplicate key (#260 by [@bbc]).
+- Fix potentially empty expanded value for duplicate key (#260 by [@bbc2]).
 - Fix import error on Python 3.5.0 and 3.5.1 (#267 by [@gongqingkui]).
+- Fix parsing of unquoted values containing several adjacent space or tab characters
+  (#277 by [@bbc2], review by [@x-yuri]).
 
 ## [0.14.0] - 2020-07-03
 
@@ -226,6 +228,7 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 [@theskumar]: https://github.com/theskumar
 [@ulyssessouza]: https://github.com/ulyssessouza
 [@venthur]: https://github.com/venthur
+[@x-yuri]: https://github.com/x-yuri
 [@yannham]: https://github.com/yannham
 
 [Unreleased]: https://github.com/theskumar/python-dotenv/compare/v0.14.0...HEAD
diff --git a/src/dotenv/parser.py b/src/dotenv/parser.py
index 4eba0ac..5cb1cdf 100644
--- a/src/dotenv/parser.py
+++ b/src/dotenv/parser.py
@@ -24,7 +24,7 @@ _unquoted_key = make_regex(r"([^=\#\s]+)")
 _equal_sign = make_regex(r"(=[^\S\r\n]*)")
 _single_quoted_value = make_regex(r"'((?:\\'|[^'])*)'")
 _double_quoted_value = make_regex(r'"((?:\\"|[^"])*)"')
-_unquoted_value_part = make_regex(r"([^ \r\n]*)")
+_unquoted_value = make_regex(r"([^\r\n]*)")
 _comment = make_regex(r"(?:[^\S\r\n]*#[^\r\n]*)?")
 _end_of_line = make_regex(r"[^\S\r\n]*(?:\r\n|\n|\r|$)")
 _rest_of_line = make_regex(r"[^\r\n]*(?:\r|\n|\r\n)?")
@@ -167,14 +167,8 @@ def parse_key(reader):
 
 def parse_unquoted_value(reader):
     # type: (Reader) -> Text
-    value = u""
-    while True:
-        (part,) = reader.read_regex(_unquoted_value_part)
-        value += part
-        after = reader.peek(2)
-        if len(after) < 2 or after[0] in u"\r\n" or after[1] in u" #\r\n":
-            return value
-        value += reader.read(2)
+    (part,) = reader.read_regex(_unquoted_value)
+    return re.sub(r"\s+#.*", "", part).rstrip()
 
 
 def parse_value(reader):

Parsing rules are somewhat unexpected
`A=1 2` (one space) works, but `A=1  2` (two spaces) produces an error. I've run into it with `docker-compose`:

`.env`:

```yaml
A=1  2
```

`docker-compose.yml`:

```yaml
version: '3'
services:
  app:
    image: alpine:3.12
    command: /app/1.sh
    env_file: .env
    volumes:
      - .:/app
```

`1.sh`:

```sh
#!/bin/sh -eux
set | grep ^A
```

```
$ docker-compose up -d && docker-compose logs -f
WARNING: Python-dotenv could not parse statement starting at line 1
WARNING: Python-dotenv could not parse statement starting at line 1
WARNING: Python-dotenv could not parse statement starting at line 1
WARNING: Python-dotenv could not parse statement starting at line 1
Creating network "overriding-vars_default" with the default driver
Creating overriding-vars_app_1 ... done
WARNING: Python-dotenv could not parse statement starting at line 1
WARNING: Python-dotenv could not parse statement starting at line 1
Attaching to overriding-vars_app_1
app_1  | + set
app_1  | + grep ^A
overriding-vars_app_1 exited with code 1
```

With `A=1 2`:

```
$ docker-compose up -d && docker-compose logs -f
Recreating overriding-vars_app_1 ... done
Attaching to overriding-vars_app_1
app_1  | + set
app_1  | + grep ^A
app_1  | A='1 2'
overriding-vars_app_1 exited with code 0
```

I'll provide a Python test case, if need be.

https://github.com/theskumar/python-dotenv/blob/v0.14.0/src/dotenv/parser.py#L175-L176
diff --git a/tests/test_parser.py b/tests/test_parser.py
index f807513..48cecdc 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -19,20 +19,40 @@ from dotenv.parser import Binding, Original, parse_stream
     (u"# a=b", [Binding(key=None, value=None, original=Original(string=u"# a=b", line=1), error=False)]),
     (u"a=b#c", [Binding(key=u"a", value=u"b#c", original=Original(string=u"a=b#c", line=1), error=False)]),
     (
-        u'a=b # comment',
-        [Binding(key=u"a", value=u"b", original=Original(string=u"a=b # comment", line=1), error=False)],
+        u'a=b #c',
+        [Binding(key=u"a", value=u"b", original=Original(string=u"a=b #c", line=1), error=False)],
     ),
     (
-        u"a=b space ",
-        [Binding(key=u"a", value=u"b space", original=Original(string=u"a=b space ", line=1), error=False)],
+        u'a=b\t#c',
+        [Binding(key=u"a", value=u"b", original=Original(string=u"a=b\t#c", line=1), error=False)],
     ),
     (
-        u"a='b space '",
-        [Binding(key=u"a", value=u"b space ", original=Original(string=u"a='b space '", line=1), error=False)],
+        u"a=b c",
+        [Binding(key=u"a", value=u"b c", original=Original(string=u"a=b c", line=1), error=False)],
     ),
     (
-        u'a="b space "',
-        [Binding(key=u"a", value=u"b space ", original=Original(string=u'a="b space "', line=1), error=False)],
+        u"a=b\tc",
+        [Binding(key=u"a", value=u"b\tc", original=Original(string=u"a=b\tc", line=1), error=False)],
+    ),
+    (
+        u"a=b  c",
+        [Binding(key=u"a", value=u"b  c", original=Original(string=u"a=b  c", line=1), error=False)],
+    ),
+    (
+        u"a=b\u00a0 c",
+        [Binding(key=u"a", value=u"b\u00a0 c", original=Original(string=u"a=b\u00a0 c", line=1), error=False)],
+    ),
+    (
+        u"a=b c ",
+        [Binding(key=u"a", value=u"b c", original=Original(string=u"a=b c ", line=1), error=False)],
+    ),
+    (
+        u"a='b c '",
+        [Binding(key=u"a", value=u"b c ", original=Original(string=u"a='b c '", line=1), error=False)],
+    ),
+    (
+        u'a="b c "',
+        [Binding(key=u"a", value=u"b c ", original=Original(string=u'a="b c "', line=1), error=False)],
     ),
     (
         u"export export_a=1",

pip install -e .[cli]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
backcall==0.2.0
bleach==4.1.0
bump2version==1.0.1
bumpversion==0.6.0
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
click==8.0.4
colorama==0.4.5
coverage==6.2
cryptography==40.0.2
dataclasses==0.7
decorator==5.1.1
distlib==0.3.9
docstring-parser==0.7.3
docutils==0.18.1
falcon==2.0.0
filelock==3.4.1
flake8==5.0.4
ghp-import==2.1.0
gitdb==4.0.9
GitPython==3.1.18
hug==2.6.1
idna==3.10
importlib-metadata==4.2.0
importlib-resources==5.4.0
iniconfig==1.1.1
ipython==7.16.3
ipython-genutils==0.2.0
jedi==0.17.2
jeepney==0.7.1
Jinja2==3.0.3
keyring==23.4.1
livereload==2.6.3
Mako==1.1.6
Markdown==3.3.4
MarkupSafe==2.0.1
mccabe==0.7.0
mergedeep==1.3.4
mkdocs==1.2.4
mkdocs-material==7.3.0
mkdocs-material-extensions==1.0.3
mock==5.2.0
packaging==21.3
parso==0.7.1
pdocs==1.1.1
pexpect==4.9.0
pickleshare==0.7.5
pkginfo==1.10.0
platformdirs==2.4.0
pluggy==1.0.0
portray==1.7.0
prompt-toolkit==3.0.36
ptyprocess==0.7.0
py==1.11.0
pycodestyle==2.9.1
pycparser==2.21
pyflakes==2.5.0
Pygments==2.14.0
pymdown-extensions==7.1
pyparsing==3.1.4
pytest==7.0.1
pytest-cov==4.0.0
python-dateutil==2.9.0.post0
-e git+https://github.com/theskumar/python-dotenv.git@6ca2e2ab399c7e41be276bc830f21af3092f5d28#egg=python_dotenv
PyYAML==6.0.1
pyyaml_env_tag==0.1
readme-renderer==34.0
requests==2.27.1
requests-toolbelt==1.0.0
rfc3986==1.5.0
SecretStorage==3.3.3
sh==1.14.3
six==1.17.0
smmap==5.0.0
toml==0.10.2
tomli==1.2.3
tornado==6.1
tox==3.28.0
tqdm==4.64.1
traitlets==4.3.3
twine==3.8.0
typing_extensions==4.1.1
urllib3==1.26.20
virtualenv==20.16.2
watchdog==2.3.1
wcwidth==0.2.13
webencodings==0.5.1
yaspin==0.15.0
zipp==3.6.0

name: python-dotenv
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - backcall==0.2.0
      - bleach==4.1.0
      - bump2version==1.0.1
      - bumpversion==0.6.0
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - click==8.0.4
      - colorama==0.4.5
      - coverage==6.2
      - cryptography==40.0.2
      - dataclasses==0.7
      - decorator==5.1.1
      - distlib==0.3.9
      - docstring-parser==0.7.3
      - docutils==0.18.1
      - falcon==2.0.0
      - filelock==3.4.1
      - flake8==5.0.4
      - ghp-import==2.1.0
      - gitdb==4.0.9
      - gitpython==3.1.18
      - hug==2.6.1
      - idna==3.10
      - importlib-metadata==4.2.0
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - ipython==7.16.3
      - ipython-genutils==0.2.0
      - jedi==0.17.2
      - jeepney==0.7.1
      - jinja2==3.0.3
      - keyring==23.4.1
      - livereload==2.6.3
      - mako==1.1.6
      - markdown==3.3.4
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - mergedeep==1.3.4
      - mkdocs==1.2.4
      - mkdocs-material==7.3.0
      - mkdocs-material-extensions==1.0.3
      - mock==5.2.0
      - packaging==21.3
      - parso==0.7.1
      - pdocs==1.1.1
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pkginfo==1.10.0
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - portray==1.7.0
      - prompt-toolkit==3.0.36
      - ptyprocess==0.7.0
      - py==1.11.0
      - pycodestyle==2.9.1
      - pycparser==2.21
      - pyflakes==2.5.0
      - pygments==2.14.0
      - pymdown-extensions==7.1
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - python-dateutil==2.9.0.post0
      - pyyaml==6.0.1
      - pyyaml-env-tag==0.1
      - readme-renderer==34.0
      - requests==2.27.1
      - requests-toolbelt==1.0.0
      - rfc3986==1.5.0
      - secretstorage==3.3.3
      - sh==1.14.3
      - six==1.17.0
      - smmap==5.0.0
      - toml==0.10.2
      - tomli==1.2.3
      - tornado==6.1
      - tox==3.28.0
      - tqdm==4.64.1
      - traitlets==4.3.3
      - twine==3.8.0
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - virtualenv==20.16.2
      - watchdog==2.3.1
      - wcwidth==0.2.13
      - webencodings==0.5.1
      - yaspin==0.15.0
      - zipp==3.6.0
prefix: /opt/conda/envs/python-dotenv

tests/test_parser.py::test_parse_stream[a=b tests/test_parser.py::test_parse_stream[a=b\t#c-expected10]
tests/test_parser.py::test_parse_stream[-expected0] tests/test_parser.py::test_parse_stream[a=b-expected1] tests/test_parser.py::test_parse_stream['a'=b-expected2] tests/test_parser.py::test_parse_stream[[=b-expected3] tests/test_parser.py::test_parse_stream[ tests/test_parser.py::test_parse_stream[export tests/test_parser.py::test_parse_stream[# tests/test_parser.py::test_parse_stream[a=b#c-expected8] tests/test_parser.py::test_parse_stream[a=b\tc-expected12] tests/test_parser.py::test_parse_stream[a=b\xa0 tests/test_parser.py::test_parse_stream[a='b tests/test_parser.py::test_parse_stream[a="b tests/test_parser.py::test_parse_stream[a="b\nc"-expected20] tests/test_parser.py::test_parse_stream[a='b\nc'-expected21] tests/test_parser.py::test_parse_stream[a="b\nc"-expected22] tests/test_parser.py::test_parse_stream[a="b\\nc"-expected23] tests/test_parser.py::test_parse_stream[a='b\\nc'-expected24] tests/test_parser.py::test_parse_stream[a="b\\"c"-expected25] tests/test_parser.py::test_parse_stream[a='b\\'c'-expected26] tests/test_parser.py::test_parse_stream[a=\xe0-expected27] tests/test_parser.py::test_parse_stream[a="\xe0"-expected28] tests/test_parser.py::test_parse_stream[no_value_var-expected29] tests/test_parser.py::test_parse_stream[a: tests/test_parser.py::test_parse_stream[a=b\nc=d-expected31] tests/test_parser.py::test_parse_stream[a=b\rc=d-expected32] tests/test_parser.py::test_parse_stream[a=b\r\nc=d-expected33] tests/test_parser.py::test_parse_stream[a=\nb=c-expected34] tests/test_parser.py::test_parse_stream[\n\n-expected35] tests/test_parser.py::test_parse_stream[a=b\n\n-expected36] tests/test_parser.py::test_parse_stream[a=b\n\nc=d-expected37] tests/test_parser.py::test_parse_stream[a="\nb=c-expected38] tests/test_parser.py::test_parse_stream[a=b\n# tests/test_parser.py::test_parse_stream[uglyKey[%$="S3cr3t_P4ssw#rD"
CHANGELOG.md src/dotenv/parser.py
CHANGELOG.md src/dotenv/parser.py