Skip to content

Commit 5ca641c

Browse files
committed
Allow optional whitespaces for Parameters::fromHttpValue
1 parent fb0ed44 commit 5ca641c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Parameters.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ public static function fromAssociative(iterable $members = []): self
101101
*/
102102
public static function fromPairs(Parameters|iterable $pairs = []): self
103103
{
104-
$instance = new self();
105104
if ($pairs instanceof Parameters) {
106-
$pairs = $pairs->toPairs();
105+
return clone $pairs;
107106
}
108107

108+
$instance = new self();
109109
foreach ($pairs as [$key, $member]) {
110110
$instance->set($key, $member);
111111
}
@@ -124,6 +124,7 @@ public static function fromPairs(Parameters|iterable $pairs = []): self
124124
public static function fromHttpValue(string $httpValue): self
125125
{
126126
$instance = new self();
127+
$httpValue = ltrim($httpValue, ' ');
127128
if ('' === $httpValue) {
128129
return $instance;
129130
}

src/ParametersTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,15 @@ public function it_fails_to_parse_invalid_parameters_pairs(): void
321321

322322
Parameters::fromHttpValue(';foo = bar');
323323
}
324+
325+
/**
326+
* @test
327+
*/
328+
public function it_successfully_parse_a_parameter_value_with_optional_white_spaces_in_front(): void
329+
{
330+
self::assertEquals(
331+
Parameters::fromHttpValue(';foo=bar'),
332+
Parameters::fromHttpValue(' ;foo=bar')
333+
);
334+
}
324335
}

0 commit comments

Comments
 (0)