Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of unquoted values with two spaces #277

Merged
merged 1 commit into from Sep 23, 2020

Conversation

bbc2
Copy link
Collaborator

@bbc2 bbc2 commented Sep 9, 2020

If a value is unquoted and has two or more adjacent spaces (like in a=b c), the parser would detect an error. This commit fixes that.

Tabs are now also considered like space characters in this case and I added relevant test cases.

Closes #276

@bbc2 bbc2 self-assigned this Sep 9, 2020
src/dotenv/parser.py Outdated Show resolved Hide resolved
If a value is unquoted and has two or more adjacent spaces (like in `a=b
c`), the parser would detect an error.  This commit fixes that.

Tabs and other whitespace characters are now also considered like space
characters in this case and I added relevant test cases.
@coveralls
Copy link

Coverage Status

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

@x-yuri
Copy link

x-yuri commented Sep 14, 2020

I was reverse-engineering the parsing rules. So I thought, maybe the README 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.

On the other hand, people might start to compose funny env files, which are incompatible with other env file parsers (that mainly concerns ignoring spaces). On yet another hand, env files parsers are incompatible as it is. And well, people might be doing it as we speak :)

@bbc2
Copy link
Collaborator Author

bbc2 commented Sep 23, 2020

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).

@bbc2 bbc2 merged commit 7b172fe into theskumar:master Sep 23, 2020
@bbc2 bbc2 deleted the fix-unquoted-double-space branch September 23, 2020 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing rules are somewhat unexpected
3 participants