PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
← All changes | vendor_prefixed/guzzlehttp/psr7/src/Rfc7230.php +70 -0 27.7 → trunk View file →
@@ -18,5 +18,75 @@
18 18 * @license https://github.com/amphp/http/blob/v1.0.1/LICENSE
19 19 */
20 20 public const HEADER_REGEX = "(^([^()<>@,;:\\\"/[\\]?={}\x01- ]++):[ \t]*+((?:[ \t]*+[!-~\x80-\xff]++)*+)[ \t]*+\r?\n)m";
21 21 public const HEADER_FOLD_REGEX = "(\r?\n[ \t]++)";
22 + /**
23 + * @return array{0: string, 1: int|null}|null
24 + */
25 + public static function parseHostHeader(string $authority) : ?array
26 + {
27 + if ($authority === '') {
28 + return null;
29 + }
30 + $host = $authority;
31 + $port = null;
32 + if ($authority[0] === '[') {
33 + $closingBracket = \strpos($authority, ']');
34 + if ($closingBracket === \false) {
35 + return null;
36 + }
37 + $host = \substr($authority, 0, $closingBracket + 1);
38 + $remainder = \substr($authority, $closingBracket + 1);
39 + if ($remainder !== '') {
40 + if ($remainder[0] !== ':') {
41 + return null;
42 + }
43 + $port = self::parseAuthorityPort(\substr($remainder, 1));
44 + if ($port === null) {
45 + return null;
46 + }
47 + }
48 + } elseif (\false !== ($colon = \strpos($authority, ':'))) {
49 + $host = \substr($authority, 0, $colon);
50 + $port = self::parseAuthorityPort(\substr($authority, $colon + 1));
51 + if ($port === null) {
52 + return null;
53 + }
54 + }
55 + if ($host === '' || !self::isValidHostHeaderHost($host)) {
56 + return null;
57 + }
58 + return [$host, $port];
59 + }
60 + private static function isValidHostHeaderHost(string $host) : bool
61 + {
62 + $invalidHost = \preg_match('/[\\x00-\\x20\\x7F\\/\\?#@\\\\]/', $host);
63 + if ($invalidHost === \false) {
64 + return \false;
65 + }
66 + if ($invalidHost === 1) {
67 + return \false;
68 + }
69 + if (\strpos($host, '[') !== \false || \strpos($host, ']') !== \false) {
70 + if ($host[0] !== '[' || \substr($host, -1) !== ']') {
71 + return \false;
72 + }
73 + $address = \substr($host, 1, -1);
74 + return \filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6) !== \false || \preg_match('/^v[0-9a-f]+\\.[' . \YoastSEO_Vendor\GuzzleHttp\Psr7\Rfc3986::CHAR_UNRESERVED . \YoastSEO_Vendor\GuzzleHttp\Psr7\Rfc3986::CHAR_SUB_DELIMS . ':]+$/iD', $address) === 1;
75 + }
76 + return \strpos($host, ':') === \false;
77 + }
78 + private static function parseAuthorityPort(string $port) : ?int
79 + {
80 + if ($port === '' || !\ctype_digit($port)) {
81 + return null;
82 + }
83 + $normalized = \ltrim($port, '0');
84 + if ($normalized === '') {
85 + return 0;
86 + }
87 + if (\strlen($normalized) > 5 || (int) $normalized > 0xffff) {
88 + return null;
89 + }
90 + return (int) $normalized;
91 + }
22 92 }