Skip to content

Commit ec18c2d

Browse files
Build/Test Tools: Correct file path normalization in HookDocBlock.
Moves the `str_replace()` call after the `false === ...` comparison so that the latter works as expected. Follow-up to r62939, r64125. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@64126 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 62e779e commit ec18c2d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎tests/phpstan/HookDocBlock.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ public function __construct( FileTypeMapper $file_type_mapper, ?string $wordpres
173173
$this->fileTypeMapper = $file_type_mapper;
174174
$this->wordpressRoot = rtrim( $wordpress_root ?? dirname( __DIR__, 2 ) . '/src', '/' );
175175

176-
$canonical_root = str_replace( '\\', '/', realpath( $this->wordpressRoot ) );
176+
$canonical_root = realpath( $this->wordpressRoot );
177177
$this->canonicalWordpressRoot = false === $canonical_root ? $this->wordpressRoot : $canonical_root;
178+
$this->canonicalWordpressRoot = str_replace( '\\', '/', $this->canonicalWordpressRoot );
178179
}
179180

180181
/**
@@ -837,12 +838,14 @@ private function resolveWithinRoot( string $candidate ): ?string {
837838
return null;
838839
}
839840

840-
$canonical = str_replace( '\\', '/', realpath( $candidate ) );
841+
$canonical = realpath( $candidate );
841842

842843
if ( false === $canonical ) {
843844
return null;
844845
}
845846

847+
$canonical = str_replace( '\\', '/', $canonical );
848+
846849
return str_starts_with( $canonical, $this->canonicalWordpressRoot . '/' ) ? $canonical : null;
847850
}
848851

0 commit comments

Comments
 (0)