Open bkdotcom opened 3 years ago
perhaps simply:
if (\preg_match('/[^\P{C}\t]/u', $phrase, $matches, PREG_OFFSET_CAPTURE) === 1) {
throw new InvalidArgumentException(\sprintf(
'Reason phrase contains a prohibited character at position %s.',
$matches[0][1]
));
}
Which will match any control character except for HTAB ("\t")
https://github.com/terrylinooo/psr-http/blob/master/src/Psr7/Response.php#L257-L262
I don't think this does what it's intended to do.
The code is testing/replacing those string literals / not the characters they represent. (preg_replace is being confused with str_replace?)
The test case is also invalid https://github.com/terrylinooo/psr-http/blob/master/tests/Psr7/ResponseTest.php#L77 '\n` and '\r' are in the test string... not "\n" and "\r"
Here's an example of a phrase that should not be allowed:
that said, here's how the reason-phrase is defined: https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2