Skip to content

[EnvConfigurator] Do not escape literal values in env files#1095

Open
DjLeChuck wants to merge 1 commit into
symfony:2.xfrom
DjLeChuck:feature/dont-escape-literals
Open

[EnvConfigurator] Do not escape literal values in env files#1095
DjLeChuck wants to merge 1 commit into
symfony:2.xfrom
DjLeChuck:feature/dont-escape-literals

Conversation

@DjLeChuck

@DjLeChuck DjLeChuck commented Jun 25, 2026

Copy link
Copy Markdown

Closes #1096

Problem

When a recipe defines a value wrapped in single quotes - for example to store a JSON array:

{
  "dotenv": {
    "dev": {
      "ALLOWED_LANGUAGES": "'[\"en\",\"de\",\"es\"]'"
    }
  }
}

The configurator incorrectly wrapped the value in double quotes and escaped the inner double quotes, producing:

ALLOWED_LANGUAGES="'[\"en\",\"de\",\"es\"]'"

Instead of the expected single-quoted dotenv literal:

ALLOWED_LANGUAGES='["en","de","es"]'

The dotenv format treats single-quoted values as fully literal strings (no escape processing), which makes them the natural fit for JSON content.

Solution

Skip the double-quote wrapping when the value already starts and ends with a single quote. Any other value continues through the existing escaping path introduced in #200.

// Before
if (false !== strpbrk($value, " \t\n&!\"")) {
  $value = '"'.str_replace([...], [...], $value).'"';
}

// After
if (!str_starts_with($value, "'") && !str_ends_with($value, "'") && false !== strpbrk($value, "\t\n&!\"")) {
  $value = '"'.str_replace([...], [...], $value).'"';
}

Tests

Added a ALLOWED_LANGUAGES='["en","de","es"]' fixture to both EnvConfiguratorTest and
DotenvConfiguratorTest to cover this case, alongside the existing assertions for values that require double-quote escaping.

@DjLeChuck DjLeChuck changed the title feat: do not escape literal values in env files Do not escape literal values in env files Jun 25, 2026
@DjLeChuck DjLeChuck changed the title Do not escape literal values in env files [EnvConfigurator] Do not escape literal values in env files Jun 25, 2026
@DjLeChuck

Copy link
Copy Markdown
Author

Should I fix Fabbot issues about code style?

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.

[EnvConfigurator] Single-quoted values are incorrectly double-quoted in .env files

1 participant