Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace WpOrg\Requests; use WpOrg\Requests\Exception; use WpOrg\Requests\Exceptio..

Decoded Output download

<?php
 namespace WpOrg\Requests; use WpOrg\Requests\Exception; use WpOrg\Requests\Exception\InvalidArgument; use WpOrg\Requests\Ipv6; use WpOrg\Requests\Port; use WpOrg\Requests\Utility\InputValidator; class Iri { protected $scheme = null; protected $iuserinfo = null; protected $ihost = null; protected $port = null; protected $ipath = ''; protected $iquery = null; protected $ifragment = null; protected $normalization = array("acap" => array("port" => Port::ACAP), "dict" => array("port" => Port::DICT), "file" => array("ihost" => "localhost"), "http" => array("port" => Port::HTTP), "https" => array("port" => Port::HTTPS)); public function __toString() { return $this->get_iri(); } public function __set($name, $value) { if (method_exists($this, "set_" . $name)) { call_user_func(array($this, "set_" . $name), $value); } elseif ($name === "iauthority" || $name === "iuserinfo" || $name === "ihost" || $name === "ipath" || $name === "iquery" || $name === "ifragment") { call_user_func(array($this, "set_" . substr($name, 1)), $value); } } public function __get($name) { $props = get_object_vars($this); if ($name === "iri" || $name === "uri" || $name === "iauthority" || $name === "authority") { $method = "get_" . $name; $return = $this->{$method}(); } elseif (array_key_exists($name, $props)) { $return = $this->{$name}; } elseif (($prop = "i" . $name) && array_key_exists($prop, $props)) { $name = $prop; $return = $this->{$prop}; } elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props)) { $name = $prop; $return = $this->{$prop}; } else { trigger_error("Undefined property: " . get_class($this) . "::" . $name, E_USER_NOTICE); $return = null; } if ($return === null && isset($this->normalization[$this->scheme][$name])) { return $this->normalization[$this->scheme][$name]; } else { return $return; } } public function __isset($name) { return method_exists($this, "get_" . $name) || isset($this->{$name}); } public function __unset($name) { if (method_exists($this, "set_" . $name)) { call_user_func(array($this, "set_" . $name), ''); } } public function __construct($iri = null) { if ($iri !== null && InputValidator::is_string_or_stringable($iri) === false) { throw InvalidArgument::create(1, "$iri", "string|Stringable|null", gettype($iri)); } $this->set_iri($iri); } public static function absolutize($base, $relative) { if (!$relative instanceof self) { $relative = new self($relative); } if (!$relative->is_valid()) { return false; } elseif ($relative->scheme !== null) { return clone $relative; } if (!$base instanceof self) { $base = new self($base); } if ($base->scheme === null || !$base->is_valid()) { return false; } if ($relative->get_iri() !== '') { if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) { $target = clone $relative; $target->scheme = $base->scheme; } else { $target = new self(); $target->scheme = $base->scheme; $target->iuserinfo = $base->iuserinfo; $target->ihost = $base->ihost; $target->port = $base->port; if ($relative->ipath !== '') { if ($relative->ipath[0] === "/") { $target->ipath = $relative->ipath; } elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') { $target->ipath = "/" . $relative->ipath; } elseif (($last_segment = strrpos($base->ipath, "/")) !== false) { $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath; } else { $target->ipath = $relative->ipath; } $target->ipath = $target->remove_dot_segments($target->ipath); $target->iquery = $relative->iquery; } else { $target->ipath = $base->ipath; if ($relative->iquery !== null) { $target->iquery = $relative->iquery; } elseif ($base->iquery !== null) { $target->iquery = $base->iquery; } } $target->ifragment = $relative->ifragment; } } else { $target = clone $base; $target->ifragment = null; } $target->scheme_normalization(); return $target; } protected function parse_iri($iri) { $iri = trim($iri, " 	\xa\xc
"); $has_match = preg_match("/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/", $iri, $match); if (!$has_match) { throw new Exception("Cannot parse supplied IRI", "iri.cannot_parse", $iri); } if ($match[1] === '') { $match["scheme"] = null; } if (!isset($match[3]) || $match[3] === '') { $match["authority"] = null; } if (!isset($match[5])) { $match["path"] = ''; } if (!isset($match[6]) || $match[6] === '') { $match["query"] = null; } if (!isset($match[8]) || $match[8] === '') { $match["fragment"] = null; } return $match; } protected function remove_dot_segments($input) { $output = ''; while (strpos($input, "./") !== false || strpos($input, "/.") !== false || $input === "." || $input === "..") { if (strpos($input, "../") === 0) { $input = substr($input, 3); } elseif (strpos($input, "./") === 0) { $input = substr($input, 2); } elseif (strpos($input, "/./") === 0) { $input = substr($input, 2); } elseif ($input === "/.") { $input = "/"; } elseif (strpos($input, "/../") === 0) { $input = substr($input, 3); $output = substr_replace($output, '', strrpos($output, "/")); } elseif ($input === "/..") { $input = "/"; $output = substr_replace($output, '', strrpos($output, "/")); } elseif ($input === "." || $input === "..") { $input = ''; } elseif (($pos = strpos($input, "/", 1)) !== false) { $output .= substr($input, 0, $pos); $input = substr_replace($input, '', 0, $pos); } else { $output .= $input; $input = ''; } } return $output . $input; } protected function replace_invalid_with_pct_encoding($text, $extra_chars, $iprivate = false) { $text = preg_replace_callback("/(?:%[A-Fa-f0-9]{2})+/", array($this, "remove_iunreserved_percent_encoded"), $text); $text = preg_replace("/%(?![A-Fa-f0-9]{2})/", "%25", $text); $extra_chars .= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%"; $position = 0; $strlen = strlen($text); while (($position += strspn($text, $extra_chars, $position)) < $strlen) { $value = ord($text[$position]); $start = $position; $valid = true; if (($value & 224) === 192) { $character = ($value & 31) << 6; $length = 2; $remaining = 1; } elseif (($value & 240) === 224) { $character = ($value & 15) << 12; $length = 3; $remaining = 2; } elseif (($value & 248) === 240) { $character = ($value & 7) << 18; $length = 4; $remaining = 3; } else { $valid = false; $length = 1; $remaining = 0; } if ($remaining) { if ($position + $length <= $strlen) { for ($position++; $remaining; $position++) { $value = ord($text[$position]); if (($value & 192) === 128) { $character |= ($value & 63) << --$remaining * 6; } else { $valid = false; $position--; break; } } } else { $position = $strlen - 1; $valid = false; } } if (!$valid || $length > 1 && $character <= 127 || $length > 2 && $character <= 2047 || $length > 3 && $character <= 65535 || ($character & 65534) === 65534 || $character >= 64976 && $character <= 65007 || ($character > 55295 && $character < 63744 || $character < 160 || $character > 983037) && (!$iprivate || $character < 57344 || $character > 1114109)) { if ($valid) { $position--; } for ($j = $start; $j <= $position; $j++) { $text = substr_replace($text, sprintf("%%%02X", ord($text[$j])), $j, 1); $j += 2; $position += 2; $strlen += 2; } } } return $text; } protected function remove_iunreserved_percent_encoded($regex_match) { $bytes = explode("%", $regex_match[0]); $string = ''; $remaining = 0; for ($i = 1, $len = count($bytes); $i < $len; $i++) { $value = hexdec($bytes[$i]); if (!$remaining) { $start = $i; $valid = true; if ($value <= 127) { $character = $value; $length = 1; } elseif (($value & 224) === 192) { $character = ($value & 31) << 6; $length = 2; $remaining = 1; } elseif (($value & 240) === 224) { $character = ($value & 15) << 12; $length = 3; $remaining = 2; } elseif (($value & 248) === 240) { $character = ($value & 7) << 18; $length = 4; $remaining = 3; } else { $valid = false; $remaining = 0; } } else { if (($value & 192) === 128) { $remaining--; $character |= ($value & 63) << $remaining * 6; } else { $valid = false; $remaining = 0; $i--; } } if (!$remaining) { if (!$valid || $length > 1 && $character <= 127 || $length > 2 && $character <= 2047 || $length > 3 && $character <= 65535 || $character < 45 || $character > 983037 || ($character & 65534) === 65534 || $character >= 64976 && $character <= 65007 || $character === 47 || $character > 57 && $character < 65 || $character > 90 && $character < 97 || $character > 122 && $character < 126 || $character > 126 && $character < 160 || $character > 55295 && $character < 63744) { for ($j = $start; $j <= $i; $j++) { $string .= "%" . strtoupper($bytes[$j]); } } else { for ($j = $start; $j <= $i; $j++) { $string .= chr(hexdec($bytes[$j])); } } } } if ($remaining) { for ($j = $start; $j < $len; $j++) { $string .= "%" . strtoupper($bytes[$j]); } } return $string; } protected function scheme_normalization() { if (isset($this->normalization[$this->scheme]["iuserinfo"]) && $this->iuserinfo === $this->normalization[$this->scheme]["iuserinfo"]) { $this->iuserinfo = null; } if (isset($this->normalization[$this->scheme]["ihost"]) && $this->ihost === $this->normalization[$this->scheme]["ihost"]) { $this->ihost = null; } if (isset($this->normalization[$this->scheme]["port"]) && $this->port === $this->normalization[$this->scheme]["port"]) { $this->port = null; } if (isset($this->normalization[$this->scheme]["ipath"]) && $this->ipath === $this->normalization[$this->scheme]["ipath"]) { $this->ipath = ''; } if (isset($this->ihost) && empty($this->ipath)) { $this->ipath = "/"; } if (isset($this->normalization[$this->scheme]["iquery"]) && $this->iquery === $this->normalization[$this->scheme]["iquery"]) { $this->iquery = null; } if (isset($this->normalization[$this->scheme]["ifragment"]) && $this->ifragment === $this->normalization[$this->scheme]["ifragment"]) { $this->ifragment = null; } } public function is_valid() { $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null; if ($this->ipath !== '' && ($isauthority && $this->ipath[0] !== "/" || $this->scheme === null && !$isauthority && strpos($this->ipath, ":") !== false && (strpos($this->ipath, "/") === false ? true : strpos($this->ipath, ":") < strpos($this->ipath, "/")))) { return false; } return true; } protected function set_iri($iri) { static $cache; if (!$cache) { $cache = array(); } if ($iri === null) { return true; } $iri = (string) $iri; if (isset($cache[$iri])) { list($this->scheme, $this->iuserinfo, $this->ihost, $this->port, $this->ipath, $this->iquery, $this->ifragment, $return) = $cache[$iri]; return $return; } $parsed = $this->parse_iri($iri); $return = $this->set_scheme($parsed["scheme"]) && $this->set_authority($parsed["authority"]) && $this->set_path($parsed["path"]) && $this->set_query($parsed["query"]) && $this->set_fragment($parsed["fragment"]); $cache[$iri] = array($this->scheme, $this->iuserinfo, $this->ihost, $this->port, $this->ipath, $this->iquery, $this->ifragment, $return); return $return; } protected function set_scheme($scheme) { if ($scheme === null) { $this->scheme = null; } elseif (!preg_match("/^[A-Za-z][0-9A-Za-z+\-.]*$/", $scheme)) { $this->scheme = null; return false; } else { $this->scheme = strtolower($scheme); } return true; } protected function set_authority($authority) { static $cache; if (!$cache) { $cache = array(); } if ($authority === null) { $this->iuserinfo = null; $this->ihost = null; $this->port = null; return true; } if (isset($cache[$authority])) { list($this->iuserinfo, $this->ihost, $this->port, $return) = $cache[$authority]; return $return; } $remaining = $authority; if (($iuserinfo_end = strrpos($remaining, "@")) !== false) { $iuserinfo = substr($remaining, 0, $iuserinfo_end); $remaining = substr($remaining, $iuserinfo_end + 1); } else { $iuserinfo = null; } if (($port_start = strpos($remaining, ":", strpos($remaining, "]"))) !== false) { $port = substr($remaining, $port_start + 1); if ($port === false || $port === '') { $port = null; } $remaining = substr($remaining, 0, $port_start); } else { $port = null; } $return = $this->set_userinfo($iuserinfo) && $this->set_host($remaining) && $this->set_port($port); $cache[$authority] = array($this->iuserinfo, $this->ihost, $this->port, $return); return $return; } protected function set_userinfo($iuserinfo) { if ($iuserinfo === null) { $this->iuserinfo = null; } else { $this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, "!$&'()*+,;=:"); $this->scheme_normalization(); } return true; } protected function set_host($ihost) { if ($ihost === null) { $this->ihost = null; return true; } if (substr($ihost, 0, 1) === "[" && substr($ihost, -1) === "]") { if (Ipv6::check_ipv6(substr($ihost, 1, -1))) { $this->ihost = "[" . Ipv6::compress(substr($ihost, 1, -1)) . "]"; } else { $this->ihost = null; return false; } } else { $ihost = $this->replace_invalid_with_pct_encoding($ihost, "!$&'()*+,;="); $position = 0; $strlen = strlen($ihost); while (($position += strcspn($ihost, "ABCDEFGHIJKLMNOPQRSTUVWXYZ%", $position)) < $strlen) { if ($ihost[$position] === "%") { $position += 3; } else { $ihost[$position] = strtolower($ihost[$position]); $position++; } } $this->ihost = $ihost; } $this->scheme_normalization(); return true; } protected function set_port($port) { if ($port === null) { $this->port = null; return true; } if (strspn($port, "0123456789") === strlen($port)) { $this->port = (int) $port; $this->scheme_normalization(); return true; } $this->port = null; return false; } protected function set_path($ipath) { static $cache; if (!$cache) { $cache = array(); } $ipath = (string) $ipath; if (isset($cache[$ipath])) { $this->ipath = $cache[$ipath][(int) ($this->scheme !== null)]; } else { $valid = $this->replace_invalid_with_pct_encoding($ipath, "!$&'()*+,;=@:/"); $removed = $this->remove_dot_segments($valid); $cache[$ipath] = array($valid, $removed); $this->ipath = $this->scheme !== null ? $removed : $valid; } $this->scheme_normalization(); return true; } protected function set_query($iquery) { if ($iquery === null) { $this->iquery = null; } else { $this->iquery = $this->replace_invalid_with_pct_encoding($iquery, "!$&'()*+,;=:@/?", true); $this->scheme_normalization(); } return true; } protected function set_fragment($ifragment) { if ($ifragment === null) { $this->ifragment = null; } else { $this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, "!$&'()*+,;=:@/?"); $this->scheme_normalization(); } return true; } protected function to_uri($iri) { if (!is_string($iri)) { return false; } static $non_ascii; if (!$non_ascii) { $non_ascii = implode('', range("\x80", "\xff")); } $position = 0; $strlen = strlen($iri); while (($position += strcspn($iri, $non_ascii, $position)) < $strlen) { $iri = substr_replace($iri, sprintf("%%%02X", ord($iri[$position])), $position, 1); $position += 3; $strlen += 2; } return $iri; } protected function get_iri() { if (!$this->is_valid()) { return false; } $iri = ''; if ($this->scheme !== null) { $iri .= $this->scheme . ":"; } if (($iauthority = $this->get_iauthority()) !== null) { $iri .= "//" . $iauthority; } $iri .= $this->ipath; if ($this->iquery !== null) { $iri .= "?" . $this->iquery; } if ($this->ifragment !== null) { $iri .= "#" . $this->ifragment; } return $iri; } protected function get_uri() { return $this->to_uri($this->get_iri()); } protected function get_iauthority() { if ($this->iuserinfo === null && $this->ihost === null && $this->port === null) { return null; } $iauthority = ''; if ($this->iuserinfo !== null) { $iauthority .= $this->iuserinfo . "@"; } if ($this->ihost !== null) { $iauthority .= $this->ihost; } if ($this->port !== null) { $iauthority .= ":" . $this->port; } return $iauthority; } protected function get_authority() { $iauthority = $this->get_iauthority(); if (is_string($iauthority)) { return $this->to_uri($iauthority); } else { return $iauthority; } } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace WpOrg\Requests; use WpOrg\Requests\Exception; use WpOrg\Requests\Exception\InvalidArgument; use WpOrg\Requests\Ipv6; use WpOrg\Requests\Port; use WpOrg\Requests\Utility\InputValidator; class Iri { protected $scheme = null; protected $iuserinfo = null; protected $ihost = null; protected $port = null; protected $ipath = ''; protected $iquery = null; protected $ifragment = null; protected $normalization = array("\x61\x63\141\160" => array("\160\x6f\162\164" => Port::ACAP), "\144\x69\143\164" => array("\x70\x6f\162\x74" => Port::DICT), "\x66\151\154\145" => array("\x69\150\x6f\x73\164" => "\x6c\x6f\143\141\154\150\157\163\x74"), "\x68\x74\x74\x70" => array("\160\157\x72\x74" => Port::HTTP), "\150\164\164\160\x73" => array("\x70\x6f\x72\x74" => Port::HTTPS)); public function __toString() { return $this->get_iri(); } public function __set($name, $value) { if (method_exists($this, "\x73\x65\164\137" . $name)) { call_user_func(array($this, "\x73\x65\x74\137" . $name), $value); } elseif ($name === "\151\x61\165\x74\150\x6f\x72\151\x74\171" || $name === "\151\165\x73\x65\x72\x69\156\146\x6f" || $name === "\151\x68\x6f\163\164" || $name === "\x69\x70\x61\x74\150" || $name === "\x69\161\165\145\x72\x79" || $name === "\x69\146\x72\141\147\155\145\x6e\x74") { call_user_func(array($this, "\x73\x65\x74\137" . substr($name, 1)), $value); } } public function __get($name) { $props = get_object_vars($this); if ($name === "\x69\162\x69" || $name === "\165\x72\151" || $name === "\x69\x61\x75\x74\x68\157\x72\x69\164\x79" || $name === "\x61\165\x74\x68\x6f\x72\x69\x74\x79") { $method = "\147\145\164\137" . $name; $return = $this->{$method}(); } elseif (array_key_exists($name, $props)) { $return = $this->{$name}; } elseif (($prop = "\x69" . $name) && array_key_exists($prop, $props)) { $name = $prop; $return = $this->{$prop}; } elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props)) { $name = $prop; $return = $this->{$prop}; } else { trigger_error("\x55\156\x64\x65\146\151\x6e\145\x64\x20\160\162\x6f\x70\145\x72\x74\x79\72\40" . get_class($this) . "\72\x3a" . $name, E_USER_NOTICE); $return = null; } if ($return === null && isset($this->normalization[$this->scheme][$name])) { return $this->normalization[$this->scheme][$name]; } else { return $return; } } public function __isset($name) { return method_exists($this, "\x67\145\x74\137" . $name) || isset($this->{$name}); } public function __unset($name) { if (method_exists($this, "\163\145\164\x5f" . $name)) { call_user_func(array($this, "\163\145\x74\x5f" . $name), ''); } } public function __construct($iri = null) { if ($iri !== null && InputValidator::is_string_or_stringable($iri) === false) { throw InvalidArgument::create(1, "\44\x69\162\x69", "\x73\x74\162\x69\156\147\x7c\123\x74\162\151\x6e\147\x61\x62\154\x65\174\x6e\x75\x6c\x6c", gettype($iri)); } $this->set_iri($iri); } public static function absolutize($base, $relative) { if (!$relative instanceof self) { $relative = new self($relative); } if (!$relative->is_valid()) { return false; } elseif ($relative->scheme !== null) { return clone $relative; } if (!$base instanceof self) { $base = new self($base); } if ($base->scheme === null || !$base->is_valid()) { return false; } if ($relative->get_iri() !== '') { if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) { $target = clone $relative; $target->scheme = $base->scheme; } else { $target = new self(); $target->scheme = $base->scheme; $target->iuserinfo = $base->iuserinfo; $target->ihost = $base->ihost; $target->port = $base->port; if ($relative->ipath !== '') { if ($relative->ipath[0] === "\57") { $target->ipath = $relative->ipath; } elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') { $target->ipath = "\x2f" . $relative->ipath; } elseif (($last_segment = strrpos($base->ipath, "\57")) !== false) { $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath; } else { $target->ipath = $relative->ipath; } $target->ipath = $target->remove_dot_segments($target->ipath); $target->iquery = $relative->iquery; } else { $target->ipath = $base->ipath; if ($relative->iquery !== null) { $target->iquery = $relative->iquery; } elseif ($base->iquery !== null) { $target->iquery = $base->iquery; } } $target->ifragment = $relative->ifragment; } } else { $target = clone $base; $target->ifragment = null; } $target->scheme_normalization(); return $target; } protected function parse_iri($iri) { $iri = trim($iri, "\40\11\xa\xc\15"); $has_match = preg_match("\57\136\50\50\x3f\120\x3c\x73\143\x68\145\155\x65\76\133\x5e\x3a\134\57\x3f\43\135\53\x29\72\x29\x3f\x28\x5c\57\134\57\x28\x3f\x50\74\141\x75\164\x68\157\x72\x69\164\x79\76\x5b\x5e\134\x2f\77\43\135\52\x29\x29\x3f\50\77\x50\x3c\160\141\x74\x68\76\133\136\77\x23\x5d\52\51\50\x5c\x3f\x28\77\x50\x3c\x71\x75\x65\162\171\76\x5b\136\x23\135\x2a\x29\x29\x3f\50\43\50\77\x50\74\x66\x72\x61\x67\155\x65\156\x74\76\x2e\52\x29\51\77\x24\x2f", $iri, $match); if (!$has_match) { throw new Exception("\x43\x61\156\156\x6f\x74\40\x70\x61\x72\163\x65\x20\163\x75\160\160\154\x69\x65\144\40\111\x52\111", "\151\x72\151\x2e\143\x61\x6e\156\157\x74\137\x70\141\162\x73\145", $iri); } if ($match[1] === '') { $match["\x73\x63\150\145\155\x65"] = null; } if (!isset($match[3]) || $match[3] === '') { $match["\x61\165\164\150\157\x72\151\164\x79"] = null; } if (!isset($match[5])) { $match["\x70\141\x74\150"] = ''; } if (!isset($match[6]) || $match[6] === '') { $match["\x71\x75\145\162\171"] = null; } if (!isset($match[8]) || $match[8] === '') { $match["\146\162\x61\x67\155\x65\156\164"] = null; } return $match; } protected function remove_dot_segments($input) { $output = ''; while (strpos($input, "\x2e\x2f") !== false || strpos($input, "\x2f\x2e") !== false || $input === "\x2e" || $input === "\56\x2e") { if (strpos($input, "\x2e\x2e\x2f") === 0) { $input = substr($input, 3); } elseif (strpos($input, "\56\x2f") === 0) { $input = substr($input, 2); } elseif (strpos($input, "\57\x2e\x2f") === 0) { $input = substr($input, 2); } elseif ($input === "\x2f\x2e") { $input = "\57"; } elseif (strpos($input, "\57\56\56\57") === 0) { $input = substr($input, 3); $output = substr_replace($output, '', strrpos($output, "\x2f")); } elseif ($input === "\57\x2e\56") { $input = "\x2f"; $output = substr_replace($output, '', strrpos($output, "\x2f")); } elseif ($input === "\56" || $input === "\x2e\56") { $input = ''; } elseif (($pos = strpos($input, "\x2f", 1)) !== false) { $output .= substr($input, 0, $pos); $input = substr_replace($input, '', 0, $pos); } else { $output .= $input; $input = ''; } } return $output . $input; } protected function replace_invalid_with_pct_encoding($text, $extra_chars, $iprivate = false) { $text = preg_replace_callback("\x2f\50\77\x3a\45\x5b\x41\x2d\106\x61\x2d\x66\60\55\x39\x5d\173\x32\175\x29\x2b\57", array($this, "\x72\x65\155\157\x76\145\137\151\x75\x6e\162\x65\x73\145\x72\x76\x65\x64\x5f\160\x65\x72\143\x65\x6e\x74\x5f\x65\156\x63\x6f\x64\145\x64"), $text); $text = preg_replace("\57\45\50\x3f\41\x5b\101\55\106\141\55\x66\x30\x2d\71\x5d\x7b\x32\175\x29\x2f", "\45\62\65", $text); $extra_chars .= "\x41\102\103\x44\x45\x46\107\110\111\112\x4b\114\115\x4e\x4f\x50\121\122\123\x54\125\126\127\x58\x59\132\141\x62\x63\144\x65\x66\x67\150\151\152\x6b\154\155\x6e\157\x70\161\x72\x73\164\165\x76\167\x78\x79\x7a\60\61\x32\x33\x34\65\66\67\x38\x39\x2d\56\x5f\x7e\x25"; $position = 0; $strlen = strlen($text); while (($position += strspn($text, $extra_chars, $position)) < $strlen) { $value = ord($text[$position]); $start = $position; $valid = true; if (($value & 224) === 192) { $character = ($value & 31) << 6; $length = 2; $remaining = 1; } elseif (($value & 240) === 224) { $character = ($value & 15) << 12; $length = 3; $remaining = 2; } elseif (($value & 248) === 240) { $character = ($value & 7) << 18; $length = 4; $remaining = 3; } else { $valid = false; $length = 1; $remaining = 0; } if ($remaining) { if ($position + $length <= $strlen) { for ($position++; $remaining; $position++) { $value = ord($text[$position]); if (($value & 192) === 128) { $character |= ($value & 63) << --$remaining * 6; } else { $valid = false; $position--; break; } } } else { $position = $strlen - 1; $valid = false; } } if (!$valid || $length > 1 && $character <= 127 || $length > 2 && $character <= 2047 || $length > 3 && $character <= 65535 || ($character & 65534) === 65534 || $character >= 64976 && $character <= 65007 || ($character > 55295 && $character < 63744 || $character < 160 || $character > 983037) && (!$iprivate || $character < 57344 || $character > 1114109)) { if ($valid) { $position--; } for ($j = $start; $j <= $position; $j++) { $text = substr_replace($text, sprintf("\45\45\x25\60\x32\130", ord($text[$j])), $j, 1); $j += 2; $position += 2; $strlen += 2; } } } return $text; } protected function remove_iunreserved_percent_encoded($regex_match) { $bytes = explode("\45", $regex_match[0]); $string = ''; $remaining = 0; for ($i = 1, $len = count($bytes); $i < $len; $i++) { $value = hexdec($bytes[$i]); if (!$remaining) { $start = $i; $valid = true; if ($value <= 127) { $character = $value; $length = 1; } elseif (($value & 224) === 192) { $character = ($value & 31) << 6; $length = 2; $remaining = 1; } elseif (($value & 240) === 224) { $character = ($value & 15) << 12; $length = 3; $remaining = 2; } elseif (($value & 248) === 240) { $character = ($value & 7) << 18; $length = 4; $remaining = 3; } else { $valid = false; $remaining = 0; } } else { if (($value & 192) === 128) { $remaining--; $character |= ($value & 63) << $remaining * 6; } else { $valid = false; $remaining = 0; $i--; } } if (!$remaining) { if (!$valid || $length > 1 && $character <= 127 || $length > 2 && $character <= 2047 || $length > 3 && $character <= 65535 || $character < 45 || $character > 983037 || ($character & 65534) === 65534 || $character >= 64976 && $character <= 65007 || $character === 47 || $character > 57 && $character < 65 || $character > 90 && $character < 97 || $character > 122 && $character < 126 || $character > 126 && $character < 160 || $character > 55295 && $character < 63744) { for ($j = $start; $j <= $i; $j++) { $string .= "\x25" . strtoupper($bytes[$j]); } } else { for ($j = $start; $j <= $i; $j++) { $string .= chr(hexdec($bytes[$j])); } } } } if ($remaining) { for ($j = $start; $j < $len; $j++) { $string .= "\45" . strtoupper($bytes[$j]); } } return $string; } protected function scheme_normalization() { if (isset($this->normalization[$this->scheme]["\151\x75\163\145\162\x69\156\146\157"]) && $this->iuserinfo === $this->normalization[$this->scheme]["\x69\165\x73\145\x72\151\x6e\146\x6f"]) { $this->iuserinfo = null; } if (isset($this->normalization[$this->scheme]["\151\150\x6f\163\164"]) && $this->ihost === $this->normalization[$this->scheme]["\151\x68\157\163\x74"]) { $this->ihost = null; } if (isset($this->normalization[$this->scheme]["\160\157\162\x74"]) && $this->port === $this->normalization[$this->scheme]["\160\157\x72\164"]) { $this->port = null; } if (isset($this->normalization[$this->scheme]["\151\160\141\164\x68"]) && $this->ipath === $this->normalization[$this->scheme]["\151\x70\141\x74\150"]) { $this->ipath = ''; } if (isset($this->ihost) && empty($this->ipath)) { $this->ipath = "\x2f"; } if (isset($this->normalization[$this->scheme]["\151\x71\x75\145\x72\171"]) && $this->iquery === $this->normalization[$this->scheme]["\151\161\x75\145\x72\x79"]) { $this->iquery = null; } if (isset($this->normalization[$this->scheme]["\x69\146\162\141\x67\155\145\156\x74"]) && $this->ifragment === $this->normalization[$this->scheme]["\x69\x66\x72\141\147\x6d\x65\156\x74"]) { $this->ifragment = null; } } public function is_valid() { $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null; if ($this->ipath !== '' && ($isauthority && $this->ipath[0] !== "\x2f" || $this->scheme === null && !$isauthority && strpos($this->ipath, "\x3a") !== false && (strpos($this->ipath, "\x2f") === false ? true : strpos($this->ipath, "\x3a") < strpos($this->ipath, "\x2f")))) { return false; } return true; } protected function set_iri($iri) { static $cache; if (!$cache) { $cache = array(); } if ($iri === null) { return true; } $iri = (string) $iri; if (isset($cache[$iri])) { list($this->scheme, $this->iuserinfo, $this->ihost, $this->port, $this->ipath, $this->iquery, $this->ifragment, $return) = $cache[$iri]; return $return; } $parsed = $this->parse_iri($iri); $return = $this->set_scheme($parsed["\163\143\150\145\155\145"]) && $this->set_authority($parsed["\x61\165\164\x68\157\x72\x69\164\x79"]) && $this->set_path($parsed["\160\141\164\150"]) && $this->set_query($parsed["\x71\165\145\x72\171"]) && $this->set_fragment($parsed["\146\x72\141\147\x6d\145\156\164"]); $cache[$iri] = array($this->scheme, $this->iuserinfo, $this->ihost, $this->port, $this->ipath, $this->iquery, $this->ifragment, $return); return $return; } protected function set_scheme($scheme) { if ($scheme === null) { $this->scheme = null; } elseif (!preg_match("\x2f\x5e\x5b\101\x2d\x5a\x61\x2d\x7a\x5d\133\x30\x2d\71\x41\55\132\x61\x2d\x7a\53\134\x2d\x2e\x5d\x2a\x24\x2f", $scheme)) { $this->scheme = null; return false; } else { $this->scheme = strtolower($scheme); } return true; } protected function set_authority($authority) { static $cache; if (!$cache) { $cache = array(); } if ($authority === null) { $this->iuserinfo = null; $this->ihost = null; $this->port = null; return true; } if (isset($cache[$authority])) { list($this->iuserinfo, $this->ihost, $this->port, $return) = $cache[$authority]; return $return; } $remaining = $authority; if (($iuserinfo_end = strrpos($remaining, "\x40")) !== false) { $iuserinfo = substr($remaining, 0, $iuserinfo_end); $remaining = substr($remaining, $iuserinfo_end + 1); } else { $iuserinfo = null; } if (($port_start = strpos($remaining, "\x3a", strpos($remaining, "\135"))) !== false) { $port = substr($remaining, $port_start + 1); if ($port === false || $port === '') { $port = null; } $remaining = substr($remaining, 0, $port_start); } else { $port = null; } $return = $this->set_userinfo($iuserinfo) && $this->set_host($remaining) && $this->set_port($port); $cache[$authority] = array($this->iuserinfo, $this->ihost, $this->port, $return); return $return; } protected function set_userinfo($iuserinfo) { if ($iuserinfo === null) { $this->iuserinfo = null; } else { $this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, "\41\44\46\47\50\51\52\53\x2c\x3b\x3d\72"); $this->scheme_normalization(); } return true; } protected function set_host($ihost) { if ($ihost === null) { $this->ihost = null; return true; } if (substr($ihost, 0, 1) === "\x5b" && substr($ihost, -1) === "\135") { if (Ipv6::check_ipv6(substr($ihost, 1, -1))) { $this->ihost = "\x5b" . Ipv6::compress(substr($ihost, 1, -1)) . "\135"; } else { $this->ihost = null; return false; } } else { $ihost = $this->replace_invalid_with_pct_encoding($ihost, "\41\x24\x26\47\x28\x29\52\x2b\54\x3b\75"); $position = 0; $strlen = strlen($ihost); while (($position += strcspn($ihost, "\101\102\103\104\105\106\107\110\111\112\113\x4c\115\116\x4f\x50\x51\122\123\124\x55\126\127\x58\131\132\45", $position)) < $strlen) { if ($ihost[$position] === "\45") { $position += 3; } else { $ihost[$position] = strtolower($ihost[$position]); $position++; } } $this->ihost = $ihost; } $this->scheme_normalization(); return true; } protected function set_port($port) { if ($port === null) { $this->port = null; return true; } if (strspn($port, "\60\x31\62\63\64\65\66\67\x38\71") === strlen($port)) { $this->port = (int) $port; $this->scheme_normalization(); return true; } $this->port = null; return false; } protected function set_path($ipath) { static $cache; if (!$cache) { $cache = array(); } $ipath = (string) $ipath; if (isset($cache[$ipath])) { $this->ipath = $cache[$ipath][(int) ($this->scheme !== null)]; } else { $valid = $this->replace_invalid_with_pct_encoding($ipath, "\41\44\46\47\x28\51\52\53\x2c\x3b\x3d\x40\72\57"); $removed = $this->remove_dot_segments($valid); $cache[$ipath] = array($valid, $removed); $this->ipath = $this->scheme !== null ? $removed : $valid; } $this->scheme_normalization(); return true; } protected function set_query($iquery) { if ($iquery === null) { $this->iquery = null; } else { $this->iquery = $this->replace_invalid_with_pct_encoding($iquery, "\41\x24\x26\47\x28\x29\x2a\53\54\x3b\75\x3a\x40\57\x3f", true); $this->scheme_normalization(); } return true; } protected function set_fragment($ifragment) { if ($ifragment === null) { $this->ifragment = null; } else { $this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, "\41\x24\46\x27\50\x29\52\x2b\54\x3b\x3d\x3a\x40\57\x3f"); $this->scheme_normalization(); } return true; } protected function to_uri($iri) { if (!is_string($iri)) { return false; } static $non_ascii; if (!$non_ascii) { $non_ascii = implode('', range("\x80", "\xff")); } $position = 0; $strlen = strlen($iri); while (($position += strcspn($iri, $non_ascii, $position)) < $strlen) { $iri = substr_replace($iri, sprintf("\x25\45\45\60\62\x58", ord($iri[$position])), $position, 1); $position += 3; $strlen += 2; } return $iri; } protected function get_iri() { if (!$this->is_valid()) { return false; } $iri = ''; if ($this->scheme !== null) { $iri .= $this->scheme . "\x3a"; } if (($iauthority = $this->get_iauthority()) !== null) { $iri .= "\57\x2f" . $iauthority; } $iri .= $this->ipath; if ($this->iquery !== null) { $iri .= "\77" . $this->iquery; } if ($this->ifragment !== null) { $iri .= "\43" . $this->ifragment; } return $iri; } protected function get_uri() { return $this->to_uri($this->get_iri()); } protected function get_iauthority() { if ($this->iuserinfo === null && $this->ihost === null && $this->port === null) { return null; } $iauthority = ''; if ($this->iuserinfo !== null) { $iauthority .= $this->iuserinfo . "\100"; } if ($this->ihost !== null) { $iauthority .= $this->ihost; } if ($this->port !== null) { $iauthority .= "\72" . $this->port; } return $iauthority; } protected function get_authority() { $iauthority = $this->get_iauthority(); if (is_string($iauthority)) { return $this->to_uri($iauthority); } else { return $iauthority; } } }

Function Calls

None

Variables

None

Stats

MD5 4ef76c406f2be1e2a4885e322861e639
Eval Count 0
Decode Time 99 ms