Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure IRI::get_iri() returns a valid URI

Technically, this is a bad idea. IRI::get_iri() should always return a
valid normalized IRI. By converting it to a URI, this causes it to be
non-normalized. However, since we're only ever using it in a URI
context, this is something I'm willing to live with.

See also 9c28bdc for `master`. Unlike
there, we can't use IRI::get_uri() instead, as that would be a break in
backwards compatibility.

Also see http://core.trac.wordpress.org/ticket/20999 for discussion
  • Loading branch information...
commit 90a771f21985e01cb0133c89631debfa951f6171 1 parent 155ff32
@rmccue rmccue authored
Showing with 26 additions and 1 deletion.
  1. +26 −1 simplepie.inc
View
27 simplepie.inc
@@ -12486,7 +12486,7 @@ class SimplePie_IRI
if ($iri !== '')
{
- return $iri;
+ return $this->to_uri($iri);
}
else
{
@@ -12495,6 +12495,31 @@ class SimplePie_IRI
}
/**
+ * Convert an IRI to a URI (or parts thereof)
+ *
+ * @return string
+ */
+ function to_uri($string)
+ {
+ static $non_ascii;
+ if (!$non_ascii)
+ {
+ $non_ascii = implode('', range("\x80", "\xFF"));
+ }
+
+ $position = 0;
+ $strlen = strlen($string);
+ while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
+ {
+ $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
+ $position += 3;
+ $strlen += 2;
+ }
+
+ return $string;
+ }
+
+ /**
* Get the scheme
*
* @access public
Please sign in to comment.
Something went wrong with that request. Please try again.