-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
94 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
# 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_VAR6=not_quoted_with_comment_beheind # var6 comment | ||
CODEGEN_TEST_VAR7=not\ quoted\ with\ escaped\ space | ||
CODEGEN_TEST_VAR8="double quoted with comment beheind" # var7 comment | ||
CODEGEN_TEST_VAR9="Variable starts with a whitespace" | ||
CODEGEN_TEST_VAR10= "Value starts with a whitespace after =" | ||
CODEGEN_TEST_VAR11 ="Variable ends with a whitespace before =" | ||
CODEGEN_TEST_MULTILINE1="First Line | ||
Second Line" | ||
CODEGEN_TEST_MULTILINE2="# First Line Comment | ||
Second Line | ||
#Third Line Comment | ||
Fourth Line | ||
" # multline2 comment | ||
|
||
# End of .env file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use dotenvy::{dotenv_iter, Error}; | ||
|
||
fn main() -> Result<(), Error> { | ||
dotenvy::dotenv()?; | ||
for item in dotenv_iter()? { | ||
let (key, val) = item?; | ||
println!("{key}={val}"); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters