Skip to content

Commit

Permalink
Merge branch '6.0' into 6.1
Browse files Browse the repository at this point in the history
* 6.0: (23 commits)
  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 6.0.12
  Update VERSION for 6.0.11
  Update CHANGELOG for 6.0.11
  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
  ...
  • Loading branch information
nicolas-grekas committed Aug 2, 2022
2 parents c780e67 + a36b782 commit 3f39c04
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
58 changes: 29 additions & 29 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 @@ -671,7 +671,7 @@ public static function join(string ...$paths): string
}

// 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 @@ -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 (str_starts_with($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 3f39c04

Please sign in to comment.