Allow \x1b (ascii ESC) in wfDebug() output
authorAntoine Musso <hashar@users.mediawiki.org>
Wed, 9 Nov 2011 10:24:54 +0000 (10:24 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Wed, 9 Nov 2011 10:24:54 +0000 (10:24 +0000)
It is a local hack I had to let me pass colored debug message using a local
wrapper:

function wfDebugGreen($msg) {
$color = "\x1b[1;32m"; # Green
$reset = "\x1b[1;0m";
wfDebug( $color . $msg . $reset );
}

Ideally \x1b should only be kept if it is followed by /(\d+(;\d)?)?+m/
which should match the 'graphic rendering' ANSI escape code.

includes/GlobalFunctions.php

index 82c1cef..0017953 100644 (file)
@@ -710,7 +710,7 @@ function wfDebug( $text, $logonly = false ) {
                if ( $wgDebugLogFile != '' && !$wgProfileOnly ) {
                        # Strip unprintables; they can switch terminal modes when binary data
                        # gets dumped, which is pretty annoying.
-                       $text = preg_replace( '![\x00-\x08\x0b\x0c\x0e-\x1f]!', ' ', $text );
+                       $text = preg_replace( '![\x00-\x08\x0b\x0c\x0e-\x1a\x1c-\x1f]!', ' ', $text );
                        $text = $wgDebugLogPrefix . $text;
                        wfErrorLog( $text, $wgDebugLogFile );
                }