Skip to content

Commit 53dac6f

Browse files
committed
fix(envlite): normalize CRLF in wp-config sample before render
wp-config-sample.php ships CRLF in tree, so the previous render path mixed the sample's CRLF lines with envlite's LF-only injections (WP_HOME, WP_SITEURL, the fetched salts block). The rendered file is then ugly and — worse — the manifest hash recorded for src/wp-config.php becomes sensitive to whatever EOL conversion the user's git client applied at checkout time, which would spuriously trip envlite's drift prompt on machines with different settings. Strip \\r\\n to \\n once at the top of envlite_phase7_render so output is LF-only regardless of how the sample was checked out. Pinned by a regression test asserting the rendered config contains no \\r\\n.
1 parent 8246054 commit 53dac6f

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

tools/local-env/envlite.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,14 @@ function envlite_phase6_install(string $repoRoot, bool $force): void {
648648
const ENVLITE_SALT_URL = 'https://api.wordpress.org/secret-key/1.1/salt/';
649649

650650
function envlite_phase7_render(string $sample, int $port, ?string $saltsBlock): string {
651+
// wp-config-sample.php ships with CRLF line endings in tree. envlite
652+
// injects LF-only lines (WP_HOME/WP_SITEURL, the salts block); without
653+
// normalization the rendered output would be a mix of CRLF and LF, which
654+
// makes envlite's recorded hash sensitive to how the user's git client
655+
// chose to check out the sample. Normalize once up front so the output
656+
// is LF-only and the hash is portable.
657+
$sample = str_replace("\r\n", "\n", $sample);
658+
651659
// 1. DB constants — exactly one of each in the sample.
652660
$dbReplacements = [
653661
'database_name_here' => 'wordpress',

tools/local-env/tests/test_phase7.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ function test_phase7_render_treats_salts_as_literal_not_backreferences() {
6363
'metacharacters in salts must survive verbatim'
6464
);
6565
}
66+
67+
function test_phase7_render_normalizes_crlf_in_sample() {
68+
// wp-config-sample.php ships CRLF in tree on a normal checkout. The
69+
// render path must normalize so the output is LF-only and the recorded
70+
// hash is stable across git EOL settings.
71+
$sample = file_get_contents(dirname(__DIR__, 3) . '/wp-config-sample.php');
72+
$out = envlite_phase7_render($sample, 8421, null);
73+
envlite_assert(strpos($out, "\r\n") === false, 'rendered config must be LF-only');
74+
}

0 commit comments

Comments
 (0)