Skip to content

Commit

Permalink
Merge pull request #17 from StyleShit/fix/windows-crlf
Browse files Browse the repository at this point in the history
fix: conditional includes are not working properly on Windows
  • Loading branch information
freekmurze committed Oct 9, 2023
2 parents 04fdb31 + 6a30c14 commit adc77d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Commenters/BladeCommenters/IncludeUnlessCommenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function pattern(): string
$excludeRegex = '(?!'.implode('|', $excludes).')';
}

return '/(?:^|\n)(\s*)@includeUnless\(([^)]+),\s*[\'"]'.$excludeRegex.'([^\'"]*)[\'"]\)/';
return '/(?:^|\n|\r\n)(\s*)@includeUnless\(([^)]+),\s*[\'"]'.$excludeRegex.'([^\'"]*)[\'"]\)/';
}

public function replacement(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Commenters/BladeCommenters/IncludeWhenCommenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function pattern(): string
$excludesRegex = '(?!'.implode('|', $excludes).')';
}

return '/(?:^|\n)(\s*)@includeWhen\(([^)]+),\s*[\'"]'.$excludesRegex.'([^\'"]*)[\'"]\)/';
return '/(?:^|\n|\r\n)(\s*)@includeWhen\(([^)]+),\s*[\'"]'.$excludesRegex.'([^\'"]*)[\'"]\)/';
}

public function replacement(): string
Expand Down
10 changes: 9 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public function rerunServiceProvider(): void
public function preparedLivewireHtmlForSnapshot(string $html): string
{
// remove all wire:* attributes
return preg_replace('/(\s+(wire:\w+)=(?<q>[\'"]).*?(?P=q))/s', '', $html);
$html = preg_replace('/(\s+(wire:[\w-]+)=(?<q>[\'"]).*?(?P=q))/s', '', $html);

// remove wire-end random string
$html = preg_replace('/wire-end:[^ ]+\s*/', '', $html);

// remove "livewire component" comment that is added only by livewire <= 2.x
$html = str_replace("\n<!-- Livewire Component -->", '', $html);

return $html;
}
}

0 comments on commit adc77d7

Please sign in to comment.