public function __toString() { $prefix = null; if ($this->protocol || $this->domain || $this->port) { $protocol = ValueAs::nonempty($this->protocol, 'http'); $auth = ''; if (strlen($this->user) && strlen($this->pass)) { $auth = SafeHtml::escapeUri($this->user) . ':' . SafeHtml::escapeUri($this->pass) . '@'; } else { if (strlen($this->user)) { $auth = SafeHtml::escapeUri($this->user) . '@'; } } if ($protocol != 'javascript') { $prefix = $protocol . '://' . $auth . $this->domain; } else { $prefix = $protocol . ':'; } if ($this->port) { $prefix .= ':' . $this->port; } } if ($this->query) { $query = '?' . http_build_query($this->query); } else { $query = null; } if (strlen($this->getFragment())) { $fragment = '#' . $this->getFragment(); } else { $fragment = null; } return $prefix . $this->getPath() . $query . $fragment; }
public function testURIEscape() { $this->assertEquals('%2B/%20%3F%23%26%3A%21xyz%25', SafeHtml::escapeUri('+/ ?#&:!xyz%')); }