-
Notifications
You must be signed in to change notification settings - Fork 48
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
Regression: Multiline support breaks .env files with quotes in comments #12
Comments
Thanks for reporting this. I will look into it. |
Hi @BlackDex, Maybe I am misunderstanding the issue. I was unable to reproduce. .env # Start of .env file
# Comment line with single ' quote
# Comment line with double " quote
TESTKEY=test_val
# End of .env file main.rs use dotenvy::{dotenv, dotenv_iter, Error};
fn main() -> Result<(), Error> {
dotenv()?;
for item in dotenv_iter()? {
let (key, val) = item?;
println!("{key}={val}"); // prints `TESTKEY=test_val`
}
Ok(())
} Could you provide more info or an example? |
@allan2 If i use the example i made above and run |
@allan2, i created a new branch on my fork to illustrate it. With that branch, within the |
The issue here is that the new Multiline iter checks every line, also if it starts with a Example of when it could be needed: # This is a comment
CODEGEN_TEST_VAR1="hello!"
CODEGEN_TEST_VAR2="'quotes within quotes'"
# This is a comment with a quote '
CODEGEN_TEST_MULTILINE1="First Line
Second Line"
CODEGEN_TEST_MULTILINE1="# First Line Comment
Second Line
#Third Line Comment
Fourth Line
" |
Fixes the line parser to respect comments when evaluating quote state. Fixes allan2#12.
Fixes a regression caused by multiline support (#12) Comments are now respected when evaluating quote state
@allan2 Unfortunately this is still an issue. It even has an other regression now. # Start of .env file
# Comment line with single ' quote
# Comment line with double " quote
# Comment line, starts with space with double " quote
CODEGEN_TEST_VAR1="hello!"
CODEGEN_TEST_VAR2="'quotes within quotes'"
CODEGEN_TEST_VAR3="double quoted with # hash in value"
CODEGEN_TEST_VAR4='single quoted with # hash in value'
CODEGEN_TEST_VAR5=not_quoted_with_#_hash_in_value
CODEGEN_TEST_VAR5=not_quoted_with_comment_beheind #_hash_in_value
# End of .env file This worked in the And the following example also breaks with the multiline feature enabled: # Start of .env file
# Comment line with single ' quote
# Comment line with double " quote
# Comment line, starts with space with double " quote
CODEGEN_TEST_VAR1="hello!"
CODEGEN_TEST_VAR2="'quotes within quotes'"
CODEGEN_TEST_VAR3="double quoted with # hash in value"
CODEGEN_TEST_VAR4='single quoted with # hash in value'
CODEGEN_TEST_VAR5=not_quoted_with_#_hash_in_value
CODEGEN_TEST_VAR5=not_quoted_with_comment_beheind #_hash_in_value
CODEGEN_TEST_MULTILINE1="First Line
Second Line"
CODEGEN_TEST_MULTILINE2="# First Line Comment
Second Line
#Third Line Comment
Fourth Line
"
# End of .env file If i just leave the |
I am also having an issue with What's happening: The line iterator, via Despite the strong quotes However, this creates problems down the line, as the line iterator is wrong, but the line parsing later on is correct. What I tried: So I escaped the source line to read However, then The only two possible outcomes are therefore:
This is a regression: As mentioned by BlackDex above, this is a |
@allan2 @LeoniePhiline i might have a fix for this: master...BlackDex:dotenvy:quote_issue |
Hmm, doesn't seem like a very good fix though. |
This PR fixes allan2#12 Added a WhiteSpace ParseState and check for a comment after a whitespace. Also return the current position of the iter to correctly strip the comments of from the line to prevent quoted comments or non-whitespace surrounded hash chars. Also updated the tests to match these cases. And added an example code to easily show the output.
This PR fixes allan2#12 Added a WhiteSpace ParseState and check for a comment after a whitespace. Also return the current position of the iter to correctly strip the comments of from the line to prevent quoted comments or non-whitespace surrounded hash chars. Also updated the tests to match these cases. And added an example code to easily show the output.
This PR fixes #12 Added a WhiteSpace ParseState and check for a comment after a whitespace. Also return the current position of the iter to correctly strip the comments of from the line to prevent quoted comments or non-whitespace surrounded hash chars. Also updated the tests to match these cases. And added an example code to easily show the output.
Hello there,
First thanks for keeping this crate alive.
I just tried to update to the latest version, but it broke my environment.
It looks like the new multiline support also checks within comments, and that breaks everything.
It is very simple to reproduce this by modifying
dotenv/tests/common/mod.rs
to this:That will create a multiline .env file to test with. And it will break.
When you remove the two lines having a double and single quote it will run again.
I didn't had time to look into this my self, but maybe @hoijui or @allan2 knows a quick fix for this :).
For now i will stick with the previous version of this crate.
The text was updated successfully, but these errors were encountered: