mathworks / dotenv-for-MATLAB

Load environment variables from a .env file.
Other
15 stars 4 forks source link

White space between variable name and equal sign "=" not supported #7

Open gwolffblues opened 1 year ago

gwolffblues commented 1 year ago

If the .env file has a field written as

MY_VAR_NAME = my_value

the parsing to a struct will fail because the struct fields cannot contain whitespaces

Recommend adding a test case here: https://github.com/mathworks/dotenv-for-MATLAB/blob/f9ba545f0468148409f7cdb7b59d24a148fc43e0/config/whitespace.env#L3

MY_VAR = my_value

Possible Solution: Change

https://github.com/mathworks/dotenv-for-MATLAB/blob/f9ba545f0468148409f7cdb7b59d24a148fc43e0/dotenv.m#L56

to

expr = "(?<key>.+?)\s*=\s*(?<value>.*)";

could also use STRTRIM on the resulting key/value string results instead

gehrhorn commented 1 year ago

@gwolffblues thanks for finding this. I don't work for MathWorks any longer so I can't fix it. I'll ping someone there to see if they could submit a fix.