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:
  [Mime] Fix TextPart broken after being serialized
  [String] CamelCase/SnakeCase on uppercase word
  • Loading branch information
fabpot committed Sep 2, 2022
2 parents 4fc8274 + 07c632d commit 3e763df
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Mime/Part/TextPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public function __sleep(): array
// convert resources to strings for serialization
if (null !== $this->seekable) {
$this->body = $this->getBody();
$this->seekable = null;
}

$this->_headers = $this->getHeaders();
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Mime/Tests/Part/TextPartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public function testSerialize()
$p = new TextPart($r);
$p->getHeaders()->addTextHeader('foo', 'bar');
$expected = clone $p;
$this->assertEquals($expected->toString(), unserialize(serialize($p))->toString());
$n = unserialize(serialize($p));
$this->assertEquals($expected->toString(), $p->toString());
$this->assertEquals($expected->toString(), $n->toString());
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/AbstractUnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function ascii(array $rules = []): self
public function camel(): static
{
$str = clone $this;
$str->string = str_replace(' ', '', preg_replace_callback('/\b./u', static function ($m) use (&$i) {
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?![A-Z]{2,})/u', static function ($m) use (&$i) {
return 1 === ++$i ? ('İ' === $m[0] ? 'i̇' : mb_strtolower($m[0], 'UTF-8')) : mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8');
}, preg_replace('/[^\pL0-9]++/u', ' ', $this->string)));

Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/String/ByteString.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public function append(string ...$suffix): static
public function camel(): static
{
$str = clone $this;
$str->string = lcfirst(str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $this->string))));

$parts = explode(' ', trim(ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $this->string))));
$parts[0] = 1 !== \strlen($parts[0]) && ctype_upper($parts[0]) ? $parts[0] : lcfirst($parts[0]);
$str->string = implode('', $parts);

return $str;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,11 +1042,13 @@ public static function provideCamel()
return [
['', ''],
['xY', 'x_y'],
['xuYo', 'xu_yo'],
['symfonyIsGreat', 'symfony_is_great'],
['symfony5IsGreat', 'symfony_5_is_great'],
['symfonyIsGreat', 'Symfony is great'],
['symfonyIsAGreatFramework', 'Symfony is a great framework'],
['symfonyIsGREAT', '*Symfony* is GREAT!!'],
['SYMFONY', 'SYMFONY'],
];
}

Expand All @@ -1066,13 +1068,15 @@ public static function provideSnake()
['', ''],
['x_y', 'x_y'],
['x_y', 'X_Y'],
['xu_yo', 'xu_yo'],
['symfony_is_great', 'symfonyIsGreat'],
['symfony5_is_great', 'symfony5IsGreat'],
['symfony5is_great', 'symfony5isGreat'],
['symfony_is_great', 'Symfony is great'],
['symfony_is_a_great_framework', 'symfonyIsAGreatFramework'],
['symfony_is_great', 'symfonyIsGREAT'],
['symfony_is_really_great', 'symfonyIsREALLYGreat'],
['symfony', 'SYMFONY'],
];
}

Expand Down

0 comments on commit 3e763df

Please sign in to comment.