Skip to content

Preserve blank lines when setting or unsetting dotenv keys - #704

Open
f14114069-del wants to merge 3 commits into
theskumar:mainfrom
f14114069-del:fix-preserve-blank-lines
Open

f14114069-del wants to merge 3 commits into
theskumar:mainfrom
f14114069-del:fix-preserve-blank-lines

Conversation

@f14114069-del

Copy link
Copy Markdown

Updating or removing a key currently also removes the blank lines immediately before that assignment. For example, changing A=old in # section\n\nA=old\n removes the separator after the section comment.

The parser includes leading whitespace in a binding's original text. Preserve the complete blank lines from that prefix before replacing or deleting the assignment. Indentation on the assignment itself retains the existing behavior.

Adds 24 parametrized regression cases covering both operations, LF and CRLF inputs, whitespace-only separators, duplicate keys, multiline values, quoted keys, and valueless keys. Updates the function docstrings and changelog.

Validation

  • New regression cases: 24 failed before the fix; 24 passed after it.
  • Windows / CPython 3.12.14 full suite: 223 passed, 50 skipped, 6 failed.
  • Unmodified upstream code, excluding the new cases: 199 passed, 50 skipped, the same 6 failed. All six require the unavailable Unix printenv executable.
  • python -m ruff check src tests: passed.
  • python -m ruff format --check src tests: passed (20 files).
  • python -m mypy --platform linux --python-version=3.12 src tests: passed. This checks Linux platform stubs; it is not a Linux runtime test. Native Windows checking encounters the existing os.mkfifo typing error in tests/test_fifo_dotenv.py:15.

AI disclosure

This patch, its tests, and this description were developed with OpenAI Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant