Skip to content

Commit c7861ba

Browse files
committed
:octocat: HeaderUtil::normalizeHeaderName(): handle spaces in header names
1 parent 0c3de78 commit c7861ba

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/HeaderUtil.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,17 @@ public static function trimValues(iterable $values):iterable{
108108
}
109109

110110
/**
111-
* Normalizes a header name, e.g. "conTENT- lenGTh" -> "Content-Length"
111+
* Normalizes a header name, e.g. "con TENT- lenGTh" -> "Content-Length"
112112
*/
113113
public static function normalizeHeaderName(string $name):string{
114-
return implode('-', array_map(fn(string $v):string => ucfirst(strtolower(trim($v))), explode('-', $name)));
114+
$parts = explode('-', $name);
115+
116+
foreach($parts as &$part){
117+
// we'll remove any spaces in the name part, e.g. "con tent" -> "content"
118+
$part = ucfirst(strtolower(str_replace(' ', '', trim($part))));
119+
}
120+
121+
return implode('-', $parts);
115122
}
116123

117124
}

tests/HeaderUtilTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static function headerDataProvider():array{
3535
'invalid: what' => [['what'], []],
3636
'empty value' => [['empty-value' => ''], ['Empty-Value' => '']],
3737
'null value' => [['null-value' => null], ['Null-Value' => '']],
38+
'space in name' => [['space name - header' => 'nope'], ['Spacename-Header' => 'nope']],
3839
];
3940
}
4041

0 commit comments

Comments
 (0)