Merge "Revert "Do not encode "'" as %27 (redirect loop in Opera 12)""
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 68e1635..2852561 100644 (file)
@@ -404,15 +404,14 @@ function wfRandomString( $length = 32 ) {
  * RFC 1738 says ~ is unsafe, however RFC 3986 considers it an unreserved
  * character which should not be encoded. More importantly, google chrome
  * always converts %7E back to ~, and converting it in this function can
- * cause a redirect loop (T105265). Similarly, encoding ' causes a
- * redirect loop on Opera 12 (T106793).
+ * cause a redirect loop (T105265).
  *
  * But + is not safe because it's used to indicate a space; &= are only safe in
- * paths and not in queries (and we don't distinguish here);
- * and urlencode() doesn't touch -_. to begin with.  Plus, although /
+ * paths and not in queries (and we don't distinguish here); ' seems kind of
+ * scary; and urlencode() doesn't touch -_. to begin with.  Plus, although /
  * is reserved, we don't care.  So the list we unescape is:
  *
- * ;:@$!*'(),/~
+ * ;:@$!*(),/~
  *
  * However, IIS7 redirects fail when the url contains a colon (Bug 22709),
  * so no fancy : for IIS7.
@@ -431,7 +430,7 @@ function wfUrlencode( $s ) {
        }
 
        if ( is_null( $needle ) ) {
-               $needle = array( '%3B', '%40', '%24', '%21', '%2A', '%27', '%28', '%29', '%2C', '%2F', '%7E' );
+               $needle = array( '%3B', '%40', '%24', '%21', '%2A', '%28', '%29', '%2C', '%2F', '%7E' );
                if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) ||
                        ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7' ) === false )
                ) {
@@ -442,7 +441,7 @@ function wfUrlencode( $s ) {
        $s = urlencode( $s );
        $s = str_ireplace(
                $needle,
-               array( ';', '@', '$', '!', '*', '\'', '(', ')', ',', '/', '~', ':' ),
+               array( ';', '@', '$', '!', '*', '(', ')', ',', '/', '~', ':' ),
                $s
        );
 
@@ -2180,14 +2179,24 @@ function wfResetOutputBuffers( $resetGzipEncoding = true ) {
                $wgDisableOutputCompression = true;
        }
        while ( $status = ob_get_status() ) {
-               if ( $status['type'] == 0 /* PHP_OUTPUT_HANDLER_INTERNAL */ ) {
-                       // Probably from zlib.output_compression or other
-                       // PHP-internal setting which can't be removed.
-                       //
+               if ( isset( $status['flags'] ) ) {
+                       $flags = PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE;
+                       $deleteable = ( $status['flags'] & $flags ) === $flags;
+               } elseif ( isset( $status['del'] ) ) {
+                       $deleteable = $status['del'];
+               } else {
+                       // Guess that any PHP-internal setting can't be removed.
+                       $deleteable = $status['type'] !== 0; /* PHP_OUTPUT_HANDLER_INTERNAL */
+               }
+               if ( !$deleteable ) {
                        // Give up, and hope the result doesn't break
                        // output behavior.
                        break;
                }
+               if ( $status['name'] === 'MediaWikiTestCase::wfResetOutputBuffersBarrier' ) {
+                       // Unit testing barrier to prevent this function from breaking PHPUnit.
+                       break;
+               }
                if ( !ob_end_clean() ) {
                        // Could not remove output buffer handler; abort now
                        // to avoid getting in some kind of infinite loop.