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

Add multi-line support #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tustvold
Copy link

@tustvold tustvold commented Sep 5, 2020

Fixes #40

@codecov
Copy link

codecov bot commented Sep 5, 2020

Codecov Report

Merging #63 into master will increase coverage by 1.04%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #63      +/-   ##
==========================================
+ Coverage   86.77%   87.82%   +1.04%     
==========================================
  Files           7        7              
  Lines         242      271      +29     
==========================================
+ Hits          210      238      +28     
- Misses         32       33       +1     
Impacted Files Coverage Δ
dotenv/src/iter.rs 93.87% <93.75%> (-0.86%) ⬇️
dotenv/src/find.rs 90.90% <0.00%> (+3.95%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c1a77b...0b99e5b. Read the comment docs.

@tustvold
Copy link
Author

tustvold commented Sep 5, 2020

The parser on master doesn't handle lines with unterminated ' or ", except where enclosed in a terminated block of the other character

For example:

KEY=asd'f => ERROR
KEY=asd'f' => asdf
KEY=asd'f'" => ERROR
KEY=asd'f'"a" => asdfa
KEY=asd'f"' => asdf"
KEY=1'2'3' => ERROR
KEY=1'2'3'4' => 1234

So this shouldn't break anything that was previously working

The implementation provided in this PR won't handle cases such as below, but I'm not sure people would expect it to

KEY='sdfsdf'"sdf
sdfsd"

On a related note, whilst experimenting I found that the parser on master doesn't handle escapes within ' which might be a bug?

KEY='\'' => ERROR
KEY="\"" => "

Copy link

@pksunkara pksunkara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Very reasonable solution too!

match self.buf.read_line(&mut buf) {
Ok(0) => return None,
Ok(_n) => {
if is_complete(&buf) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me like it would cause an exponential slowdown if a quote contained a large number of lines - it would have to loop through every character read so far for each new line.

Would it be possible to make this a stateful parser which keeps track of what quotes have been seen so far, and only looks at each character once be possible without making it significantly more complicated?

I mean, the current code won't slow down any current use cases, and env variables are unlikely to be very large. But it seems non-ideal to have an exponential slowdown if it's avoidable?

I'm asking as an observer: I don't have any ownership over dotenv.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a go at it

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have it working:
#78

@hoijui
Copy link

hoijui commented Mar 7, 2022

superseded by allan2#3

@hoijui hoijui mentioned this pull request Jul 14, 2022
noizwaves added a commit to oscope-dev/scope that referenced this pull request Apr 11, 2024
dotenv appears unmaintained and [does not support multiline
values](dotenv-rs/dotenv#63) yet. Replace this
with a the well maintained fork
[dotenvy](https://crates.io/crates/dotenvy).

## Testing
Ran `scope doctor run` locally and confirmed it successfully reads
multi-line env vars correctly.
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.

Support multiline values
5 participants