Skip to content

Commit

Permalink
Fixed escaping in file processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed May 28, 2024
1 parent c9e785c commit 7509b71
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CustomizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public static function replaceInPath(string $path, string $search, string $repla
$new_content = preg_replace($search, $replace, $file_content);
}
elseif ($replace_line) {
$new_content = preg_replace(sprintf('/^.*%s.*/m', $search), $replace, $file_content);
$new_content = preg_replace(sprintf('/^.*%s.*\R?/m', preg_quote($search, '/')), $replace, $file_content);
}
else {
$new_content = str_replace($search, $replace, $file_content);
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/Unit/FilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,33 @@ public static function dataProviderReplaceInPath(): array {
],
],

// Single file - whole string - complex.
[
'.',
[
'file1.txt' => "First line of the first file\nUnique string\nnon-uni/que string",
],
'non-uni/que',
'other who/le new string',
TRUE,
[
'file1.txt' => "First line of the first file\nUnique string\nother who/le new string",
],
],

[
'.',
[
'file2.txt' => "First line of the first file\nnon-unique\nstring",
],
'non-unique',
'',
TRUE,
[
'file2.txt' => "First line of the first file\nstring",
],
],

// Tree - only word.
[
'.',
Expand Down

0 comments on commit 7509b71

Please sign in to comment.