Unterminated double-quoted value at end of input is silently dropped

Open Beginner friendly
#610 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Start at Lines::process() for input passed to Dotenv::parse(); compare end-of-input handling with the single-quoted path and the transducer's existing missing-closing-quote behavior. Done means unterminated double-quoted input raises that error, does not swallow later lines, and properly closed multiline values remain unchanged.

Written by the indexing model from the issue text.

Description

When a double-quoted value is left unterminated at the end of the input, the whole entry and every line after it are dropped with no error. This is inconsistent with the single-quoted case, which reports a missing closing quote, so a stray quote can silently erase configuration rather than failing loudly.

Dotenv::parse('FOO="bar');            // returns [] — no exception
Dotenv::parse("A=\"oops\nB=keep");    // returns [] — B is swallowed too
Dotenv::parse("FOO='bar");            // correctly throws "a missing closing quote"

The cause is in Lines::process(): when the input ends while still inside a multiline value, the buffered content is discarded instead of being handed to the parser. Emitting the still-open buffer sends it to the transducer, which then reports the same "missing closing quote" error the single-quoted path already produces, and stops swallowing the following lines. A properly closed multiline value is unaffected.

This is a behaviour change rather than a pure bugfix, since input that currently returns an empty or partial array would start throwing. The current behaviour is silent data loss so the fix is well justified, but under SemVer it belongs in the next major rather than a 5.x release.

Dominant language
PHP
Stars
13.6k
Forks
664
Avg merge
11h 2m
Merged PRs (30d)
15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vlucas/phpdotenv

All issues in vlucas/phpdotenv

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.