Skip to content

Commit 9149879

Browse files
committed
🐛 Bug Fix
Layout content merge: Fixed preg_replace backreference issue in layout content insertion - preg_replace(pattern, $html, $layoutHtml) treated $ and \ in page content as regex backreferences - Content containing $2a$04$... (e.g., bcrypt hashes) was corrupted: $2 -> empty, $04 -> empty -> result: a$.j0S6... - Fix: Escape \ and $ in replacement string using str_replace before passing to preg_replace
1 parent f8cdf4c commit 9149879

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/Engine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ private function convertTemplate(string $templatePath, array $data): string
232232

233233
// insert content into layout
234234
if (preg_match(self::PATTERN['content'], $layoutHtml)) {
235-
$html = preg_replace(self::PATTERN['content'], $html, $layoutHtml);
235+
$html = preg_replace(self::PATTERN['content'], str_replace(['\\', '$'], ['\\\\', '\\$'], $html), $layoutHtml);
236236
} else {
237237
throw new Exception("Content Comment not has " . $layoutPath . " file\n" . "need \"" . str_replace('/', '', self::PATTERN['content']) . "\" comment in layout file");
238238
}

0 commit comments

Comments
 (0)