Fix env file quote stripping for mixed-quote values#138
Conversation
Replace .strip("\"'") with matched-pair quote detection in both
parse_env_file() and the protected env parser in load_config().
str.strip(chars) removes any character in the set from both ends
independently, so KEY='he said "hello"' would lose the trailing
double quote, yielding a corrupted value. The new _strip_quotes()
helper only strips when the first and last characters are the same
quote type.
Fixes #131
Review by KaiPR Review: Fix env file quote stripping for mixed-quote valuesOverall: Clean fix. No bugs, no security issues. Minor suggestions only. Logic / CorrectnessThe The fix is applied consistently to both manual parse paths ( SecurityNo concerns. If anything, the old behavior was the mild hazard — silently corrupting credential values containing embedded quotes. Edge cases not covered (suggestions only)Suggestion — Escape sequences inside quoted values (e.g. Suggestion — StyleTests are well-named and cover the decision boundaries cleanly. The Verdict: Approve. The fix is minimal, correct, and the test coverage is thorough. |
Summary
.strip("\"'")with matched-pair quote detection in both env file parsing pathsstr.strip(chars)treats its argument as a set of characters, removing any from both ends independently - soKEY='he said "hello"'loses the trailing"because it is in the strip set, yielding a corrupted value_strip_quotes()helper only strips when the first and last characters are the same quote typeparse_env_file()and the protected env parser inload_config()python-dotenvcode path already handles this correctly; only the manual fallback parsers were affectedTest plan
_strip_quotesunit tests: matched double, matched single, mismatched, no quotes, empty string, single char quote, empty quoted string, inner quotes preserved (8 tests)parse_env_fileintegration tests: single quotes containing double, double containing single, mismatched not stripped, unquoted unchanged, single quote char unchanged (5 tests)test_quoted_values(simple"hello"and'world') still passesmake checkcleanFixes #131