-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
StringIndexOutOfBoundsException for broken .env file while using ignoreIfMalformed #63
Comments
would you be interested in posting a PR? |
You could just change private final Predicate<String> isQuoted = s -> s.length() > 1 && s.startsWith("\"") && s.endsWith("\""); Or change private String normalizeValue(final String value) {
final var tr = value.trim();
if (isQuoted.test(tr)) {
return tr.length() > 1 ? tr.substring(1, tr.length() - 1) : "";
}
return tr;
} (I just noticed that Or change the last line of if (value.equals("\"")) {
if (throwIfMalformed)
throw new DotenvException("Malformed entry " + line);
return;
}
entries.add(new DotenvEntry(key, value)); Depending on what you think should happen. I just think there shouldn't an exception be thrown when |
cdimascio
pushed a commit
that referenced
this issue
Sep 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this deliberately really broken
.env
file to test stuff, and dotenv-java crashes with an StringIndexOutOfBoundsException on it. Is theignoreIfMalformed
option supposed to catch these or is this out of scope for this library?The problem is that
isQuoted()
checks if the value starts and ends with"
, but not that it is longer than a single character, and laternormalizeValue()
tries to slice of a character from the start and end.Backtrace:
The text was updated successfully, but these errors were encountered: