Skip to content

Commit f9fb465

Browse files
kayw-geeksebastianbergmann
authored andcommitted
Only quote INI value when it contains ; or " (preserve On/Off semantics)
1 parent 1afa115 commit f9fb465

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/Util/PHP/JobRunner.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use function is_resource;
2727
use function proc_close;
2828
use function proc_open;
29+
use function str_contains;
2930
use function str_replace;
3031
use function str_starts_with;
3132
use function stream_get_contents;
@@ -335,9 +336,14 @@ private function settingsToParameters(array $settings): array
335336
}
336337

337338
/**
338-
* Wraps the value portion of a "name=value" INI setting in double quotes
339-
* so PHP's INI parser treats characters such as `;` (comment) and `"`
340-
* (string delimiter) as literal data instead of metacharacters.
339+
* Quotes the value portion of a "name=value" INI setting only when it
340+
* contains characters PHP's INI parser would otherwise interpret as
341+
* metacharacters (`;` starts a comment, `"` is a string delimiter).
342+
*
343+
* Quoting is avoided for plain values so that boolean keywords such as
344+
* `On` / `Off` keep their special INI semantics; wrapping them in quotes
345+
* turns them into the literal strings `"On"` / `"Off"` and breaks
346+
* settings like `output_buffering`.
341347
*/
342348
private function quoteSettingValue(string $setting): string
343349
{
@@ -347,9 +353,14 @@ private function quoteSettingValue(string $setting): string
347353
return $setting;
348354
}
349355

350-
$name = substr($setting, 0, $position);
351356
$value = substr($setting, $position + 1);
352357

358+
if (!str_contains($value, ';') && !str_contains($value, '"')) {
359+
return $setting;
360+
}
361+
362+
$name = substr($setting, 0, $position);
363+
353364
return $name . '="' . str_replace('"', '\\"', $value) . '"';
354365
}
355366
}

0 commit comments

Comments
 (0)