dotenv-java icon indicating copy to clipboard operation
dotenv-java copied to clipboard

Improvement on filename() method

Open saiema opened this issue 11 months ago • 2 comments

When calling Dotenv.configure().filename(F), there is no check if F is an absolute path, leading to always prepending ./, except of course directory() is called with "" as argument.

I don't believe this to be a bug, but this could be improved with a simple check on the filename argument.

Kind regards,

Simon.

saiema avatar Jan 27 '25 22:01 saiema

@saiema thanks for the ticket. note that filename should not be a file path, but simply a filename. doc

it is used when the name of the .env is something other than .env, for instance env or my-custom-env-file.ext, etc

directory (doc) is help Dotenv find the .env file.

does this help? perhaps some validation to ensure F in filename(F) is not a path may help avoid confusion.

cdimascio avatar Mar 19 '25 01:03 cdimascio

Dear @cdimascio,

I think I misread the filename method's documentation, maybe I thought that the argument was a path when it was just a name.

I don't think a validation in method filename is required, null and non-empty validations would be much better than validating that the argument is not a path. I don't see any code dealing with a null or empty filename.

Kind regards.

saiema avatar Mar 19 '25 06:03 saiema