Skip to content

Commit 89cb450

Browse files
committed
Detect leading spaces in config files
Because those will cause PHP to output to stdout and will cause unrelated error messages. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
1 parent 9475cc0 commit 89cb450

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/private/Config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ private function readData() {
231231

232232
unset($CONFIG);
233233
include $file;
234+
if (!defined('PHPUNIT_RUN') && headers_sent()) {
235+
// syntax issues in the config file like leading spaces causing PHP to send output
236+
$errorMessage = sprintf('Config file has leading content, please remove everything before "<?php" in %s', basename($file));
237+
if (!defined('OC_CONSOLE')) {
238+
print(\OCP\Util::sanitizeHTML($errorMessage));
239+
}
240+
throw new \Exception($errorMessage);
241+
}
234242
if (isset($CONFIG) && is_array($CONFIG)) {
235243
$this->cache = array_merge($this->cache, $CONFIG);
236244
}

0 commit comments

Comments
 (0)