66
77use Rector \Configuration \Option ;
88use Rector \Exception \ShouldNotHappenException ;
9+ use Rector \Skipper \FileSystem \PathNormalizer ;
910use Webmozart \Assert \Assert ;
1011
1112/**
@@ -222,15 +223,23 @@ private static function relativizeProjectPaths(array $parameters, string $projec
222223 continue ;
223224 }
224225
225- if (is_string ($ value ) && str_starts_with ($ value , $ projectPathPrefix )) {
226- $ parameters [$ key ] = substr ($ value , strlen ($ projectPathPrefix ));
226+ if (! is_string ($ value )) {
227+ continue ;
228+ }
229+
230+ // compared with normalized separators: on Windows getcwd() reports backslashes,
231+ // while a config path built with "/" keeps them, although both name the same directory
232+ $ normalizedValue = PathNormalizer ::normalize ($ value );
233+ if (str_starts_with ($ normalizedValue , $ projectPathPrefix )) {
234+ $ parameters [$ key ] = substr ($ normalizedValue , strlen ($ projectPathPrefix ));
227235 }
228236 }
229237
230238 return $ parameters ;
231239 }
232240
233241 /**
242+ * Normalized to "/" separators, so the prefix compares alike with config paths on every platform.
234243 * Empty when the working directory cannot be resolved, which makes the relativizing above a
235244 * no-op rather than a wrong answer.
236245 */
@@ -241,7 +250,7 @@ private static function projectPathPrefix(): string
241250 return '' ;
242251 }
243252
244- return rtrim ($ currentDirectory , '/ ' ) . '/ ' ;
253+ return rtrim (PathNormalizer :: normalize ( $ currentDirectory) , '/ ' ) . '/ ' ;
245254 }
246255
247256 /**
0 commit comments