Skip to content

Commit cc82955

Browse files
committed
Fix URL paths ending in / not matching ignores
1 parent 742bcfb commit cc82955

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/FileIgnorePattern.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class FileIgnorePattern {
1919
*/
2020
private $regex;
2121

22+
/**
23+
* @var string
24+
* Regex tested against relative URLs.
25+
*/
26+
private $url_regex;
27+
2228
/**
2329
* Following gitignore rules:
2430
* - Patterns ending in / match only directories.
@@ -49,7 +55,9 @@ public function __construct(
4955
// Make it case-insensitive
5056
$this->regex = $regex . 'i';
5157

52-
// WsLog::l("Created regex $this->regex for pattern $pattern");
58+
// URL paths can match with or without trailing /
59+
$url_regex = Pattern::make( $pattern )->toRegex( Pattern::START_ANCHOR );
60+
$this->url_regex = substr( $url_regex, 0, -1 ) . '/?$#i';
5361
}
5462

5563
public function matches(
@@ -69,8 +77,8 @@ public function matches(
6977
public function matchesPath(
7078
string $path,
7179
): bool {
72-
if ( preg_match( $this->regex, $path ) ) {
73-
WsLog::d( "Ignoring $path with regex $this->regex" );
80+
if ( preg_match( $this->url_regex, $path ) ) {
81+
WsLog::d( "Ignoring $path with regex $this->url_regex" );
7482
return true;
7583
}
7684

0 commit comments

Comments
 (0)