r38908 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38907‎ | r38908 | r38909 >
Date:15:45, 8 August 2008
Author:simetrical
Status:old
Tags:
Comment:
Unescape more "safe" characters when producing URLs, for added prettiness. Checked against RFC 1738; should cause no problems if wfUrlencode() is only applied to bits of the URL after the domain name. And if it is applied to the domain name or protocol as well, this is probably less broken, if anything, not more, since hex escapes aren't permitted in the domain name or protocol part.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -151,16 +151,31 @@
152152 }
153153
154154 /**
155 - * We want / and : to be included as literal characters in our title URLs.
 155+ * We want some things to be included as literal characters in our title URLs
 156+ * for prettiness, which urlencode encodes by default. According to RFC 1738,
 157+ * all of the following should be safe:
 158+ *
 159+ * ;:@&=$-_.+!*'(),
 160+ *
 161+ * But + is not safe because it's used to indicate a space; &= are only safe in
 162+ * paths and not in queries (and we don't distinguish here); ' seems kind of
 163+ * scary; and urlencode() doesn't touch -_. to begin with. Plus, although /
 164+ * is reserved, we don't care. So the list we unescape is:
 165+ *
 166+ * ;:@$!*(),/
 167+ *
156168 * %2F in the page titles seems to fatally break for some reason.
157169 *
158170 * @param $s String:
159171 * @return string
160172 */
161 -function wfUrlencode ( $s ) {
 173+function wfUrlencode( $s ) {
162174 $s = urlencode( $s );
163 - $s = preg_replace( '/%3[Aa]/', ':', $s );
164 - $s = preg_replace( '/%2[Ff]/', '/', $s );
 175+ $s = str_ireplace(
 176+ array( '%3B','%3A','%40','%24','%21','%2A','%28','%29','%2C','%2F' ),
 177+ array( ';', ':', '@', '$', '!', '*', '(', ')', ',', '/' ),
 178+ $s
 179+ );
165180
166181 return $s;
167182 }
Index: trunk/phase3/RELEASE-NOTES
@@ -57,6 +57,7 @@
5858 being converted or not
5959 * (bug 14921) Special:Contributions/: add user name to <title>
6060 Patch by Emufarmers
 61+* Unescape more "safe" characters when producing URLs, for added prettiness
6162
6263 === Bug fixes in 1.14 ===
6364

Status & tagging log