Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  cs fix
  [Messenger] Fix Doctrine transport on MySQL
  [Filesystem] Remove needless `mb_*` calls
  [Translator] Fix translator overlapse
  [Yaml] Improve test coverage in DumperTest and ParserTest
  Extract dispatching console signal handling and include subscribers
  [Mailer] Fix error message in case of an STMP error
  [HttpClient] Fix shared connections not being freed on PHP < 8
  [HttpFoundation] Fix invalid ID not regenerated with native PHP file sessions
  [HttpClient] Fix memory leak when using StreamWrapper
  minor: fix test
  [Serializer] Fix error message
  remove the ChatterInterface alias when the chatter service is removed
  Bump Symfony version to 5.4.12
  Update VERSION for 5.4.11
  Update CHANGELOG for 5.4.11
  Bump Symfony version to 4.4.45
  Update VERSION for 4.4.44
  Update CONTRIBUTORS for 4.4.44
  Update CHANGELOG for 4.4.44
  • Loading branch information
nicolas-grekas committed Aug 2, 2022
2 parents 33787a6 + 2d67c1f commit a36b782
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
68 changes: 34 additions & 34 deletions Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function canonicalize(string $path): string

// Replace "~" with user's home directory.
if ('~' === $path[0]) {
$path = self::getHomeDirectory().mb_substr($path, 1);
$path = self::getHomeDirectory().substr($path, 1);
}

$path = self::normalize($path);
Expand Down Expand Up @@ -151,14 +151,14 @@ public static function getDirectory(string $path): string
$path = self::canonicalize($path);

// Maintain scheme
if (false !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) {
$scheme = mb_substr($path, 0, $schemeSeparatorPosition + 3);
$path = mb_substr($path, $schemeSeparatorPosition + 3);
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
$scheme = substr($path, 0, $schemeSeparatorPosition + 3);
$path = substr($path, $schemeSeparatorPosition + 3);
} else {
$scheme = '';
}

if (false === ($dirSeparatorPosition = strrpos($path, '/'))) {
if (false === $dirSeparatorPosition = strrpos($path, '/')) {
return '';
}

Expand All @@ -169,10 +169,10 @@ public static function getDirectory(string $path): string

// Directory equals Windows root "C:/"
if (2 === $dirSeparatorPosition && ctype_alpha($path[0]) && ':' === $path[1]) {
return $scheme.mb_substr($path, 0, 3);
return $scheme.substr($path, 0, 3);
}

return $scheme.mb_substr($path, 0, $dirSeparatorPosition);
return $scheme.substr($path, 0, $dirSeparatorPosition);
}

/**
Expand Down Expand Up @@ -219,7 +219,7 @@ public static function getRoot(string $path): string
}

// Maintain scheme
if (false !== ($schemeSeparatorPosition = strpos($path, '://'))) {
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
$scheme = substr($path, 0, $schemeSeparatorPosition + 3);
$path = substr($path, $schemeSeparatorPosition + 3);
} else {
Expand All @@ -233,7 +233,7 @@ public static function getRoot(string $path): string
return $scheme.'/';
}

$length = mb_strlen($path);
$length = \strlen($path);

// Windows root
if ($length > 1 && ':' === $path[1] && ctype_alpha($firstCharacter)) {
Expand Down Expand Up @@ -349,16 +349,16 @@ public static function changeExtension(string $path, string $extension): string
$extension = ltrim($extension, '.');

// No extension for paths
if ('/' === mb_substr($path, -1)) {
if ('/' === substr($path, -1)) {
return $path;
}

// No actual extension in path
if (empty($actualExtension)) {
return $path.('.' === mb_substr($path, -1) ? '' : '.').$extension;
return $path.('.' === substr($path, -1) ? '' : '.').$extension;
}

return mb_substr($path, 0, -mb_strlen($actualExtension)).$extension;
return substr($path, 0, -\strlen($actualExtension)).$extension;
}

public static function isAbsolute(string $path): bool
Expand All @@ -368,8 +368,8 @@ public static function isAbsolute(string $path): bool
}

// Strip scheme
if (false !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) {
$path = mb_substr($path, $schemeSeparatorPosition + 3);
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
$path = substr($path, $schemeSeparatorPosition + 3);
}

$firstCharacter = $path[0];
Expand All @@ -380,9 +380,9 @@ public static function isAbsolute(string $path): bool
}

// Windows root
if (mb_strlen($path) > 1 && ctype_alpha($firstCharacter) && ':' === $path[1]) {
if (\strlen($path) > 1 && ctype_alpha($firstCharacter) && ':' === $path[1]) {
// Special case: "C:"
if (2 === mb_strlen($path)) {
if (2 === \strlen($path)) {
return true;
}

Expand Down Expand Up @@ -451,9 +451,9 @@ public static function makeAbsolute(string $path, string $basePath): string
return self::canonicalize($path);
}

if (false !== ($schemeSeparatorPosition = mb_strpos($basePath, '://'))) {
$scheme = mb_substr($basePath, 0, $schemeSeparatorPosition + 3);
$basePath = mb_substr($basePath, $schemeSeparatorPosition + 3);
if (false !== $schemeSeparatorPosition = strpos($basePath, '://')) {
$scheme = substr($basePath, 0, $schemeSeparatorPosition + 3);
$basePath = substr($basePath, $schemeSeparatorPosition + 3);
} else {
$scheme = '';
}
Expand Down Expand Up @@ -574,7 +574,7 @@ public static function makeRelative(string $path, string $basePath): string
*/
public static function isLocal(string $path): bool
{
return '' !== $path && false === mb_strpos($path, '://');
return '' !== $path && false === strpos($path, '://');
}

/**
Expand Down Expand Up @@ -638,7 +638,7 @@ public static function getLongestCommonBasePath(string ...$paths): ?string

// Prevent false positives for common prefixes
// see isBasePath()
if (0 === mb_strpos($path.'/', $basePath.'/')) {
if (0 === strpos($path.'/', $basePath.'/')) {
// next path
continue 2;
}
Expand Down Expand Up @@ -666,12 +666,12 @@ public static function join(string ...$paths): string
if (null === $finalPath) {
// For first part we keep slashes, like '/top', 'C:\' or 'phar://'
$finalPath = $path;
$wasScheme = (false !== mb_strpos($path, '://'));
$wasScheme = (false !== strpos($path, '://'));
continue;
}

// Only add slash if previous part didn't end with '/' or '\'
if (!\in_array(mb_substr($finalPath, -1), ['/', '\\'])) {
if (!\in_array(substr($finalPath, -1), ['/', '\\'])) {
$finalPath .= '/';
}

Expand Down Expand Up @@ -717,7 +717,7 @@ public static function isBasePath(string $basePath, string $ofPath): bool
// Don't append a slash for the root "/", because then that root
// won't be discovered as common prefix ("//" is not a prefix of
// "/foobar/").
return 0 === mb_strpos($ofPath.'/', rtrim($basePath, '/').'/');
return 0 === strpos($ofPath.'/', rtrim($basePath, '/').'/');
}

/**
Expand Down Expand Up @@ -776,28 +776,28 @@ private static function split(string $path): array
}

// Remember scheme as part of the root, if any
if (false !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) {
$root = mb_substr($path, 0, $schemeSeparatorPosition + 3);
$path = mb_substr($path, $schemeSeparatorPosition + 3);
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
$root = substr($path, 0, $schemeSeparatorPosition + 3);
$path = substr($path, $schemeSeparatorPosition + 3);
} else {
$root = '';
}

$length = mb_strlen($path);
$length = \strlen($path);

// Remove and remember root directory
if (0 === mb_strpos($path, '/')) {
if (0 === strpos($path, '/')) {
$root .= '/';
$path = $length > 1 ? mb_substr($path, 1) : '';
$path = $length > 1 ? substr($path, 1) : '';
} elseif ($length > 1 && ctype_alpha($path[0]) && ':' === $path[1]) {
if (2 === $length) {
// Windows special case: "C:"
$root .= $path.'/';
$path = '';
} elseif ('/' === $path[2]) {
// Windows normal case: "C:/"..
$root .= mb_substr($path, 0, 3);
$path = $length > 3 ? mb_substr($path, 3) : '';
$root .= substr($path, 0, 3);
$path = $length > 3 ? substr($path, 3) : '';
}
}

Expand All @@ -806,11 +806,11 @@ private static function split(string $path): array

private static function toLower(string $string): string
{
if (false !== $encoding = mb_detect_encoding($string)) {
if (false !== $encoding = mb_detect_encoding($string, null, true)) {
return mb_strtolower($string, $encoding);
}

return strtolower($string, $encoding);
return strtolower($string);
}

private function __construct()
Expand Down
2 changes: 2 additions & 0 deletions Tests/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ public function provideGetDirectoryTests(): \Generator
yield ['/..', '/'];

yield ['C:webmozart', ''];

yield ['D:/Folder/Aééé/Subfolder', 'D:/Folder/Aééé'];
}

/**
Expand Down

0 comments on commit a36b782

Please sign in to comment.