[web-doc] master: This is more secure.

From: Date: Wed, 19 May 2021 01:35:18 +0000
Subject: [web-doc] master: This is more secure.
Groups: php.doc.web 
Request: Send a blank email to doc-web+get-2476@lists.php.net to get a copy of this message
Author: Nilgün Belma Bugüner (nilgun) Date: 2021-05-19T04:35:20+03:00 Commit: https://github.com/php/web-doc/commit/e9f815f45a498c62f8f89a1a76f159b0b7988949 Raw diff: https://github.com/php/web-doc/commit/e9f815f45a498c62f8f89a1a76f159b0b7988949.diff This is more secure. Changed paths: M include/lib_revcheck.inc.php M www/revcheck.php Diff: diff --git a/include/lib_revcheck.inc.php b/include/lib_revcheck.inc.php index 61f4768..4adc715 100644 --- a/include/lib_revcheck.inc.php +++ b/include/lib_revcheck.inc.php @@ -238,6 +238,34 @@ function get_stats($idx, $lang, $status) { return array($result['total'], $result['size']); } +function showdiff ( $dir, $gitfile, $h2, $c ) +{ + $cwd = getcwd(); + chdir( $dir ); + $file = git diff {$h2} -- {$gitfile}; + chdir( $cwd ); + $raw = htmlspecialchars( $file, ENT_XML1, 'UTF-8' ); + if ( $c == 'on' ) { + $trans = [ " " => "&nbsp;" ]; + $lines = explode ( "\n" , $raw ); + foreach ( $lines as $line ) { + $inline = strtr( $line , $trans ); + $fc = substr( $inline , 0 , 1 ); + if ( $fc == "+" ) { + echo "<div style='color:green;font-family:mono'>"; + } elseif ( $fc == "-" ) { + echo "<div style='color:red;font-family:mono'>"; + } elseif ( $fc == "@" ) { + echo "<div style='color:blue;font-family:mono'>"; + } else + echo "<div style='color:gray;font-family:mono'>"; + echo "$inline</div>\n"; + } + echo "<p></p>"; + } else + echo "<pre style='font-family:mono'>" , $raw , "</pre>"; +} + function gen_date($file) { $unix = filemtime($file); diff --git a/www/revcheck.php b/www/revcheck.php index cd86030..ae4f60d 100644 --- a/www/revcheck.php +++ b/www/revcheck.php @@ -386,35 +386,11 @@ $gitfile = $_GET['f']; if (isset($_GET['hbp'])) $h2 = $_GET['hbp']; - $cwd = getcwd(); - chdir( GIT_DIR . 'en' ); - $file = git diff {$h2} -- {$gitfile}; - chdir( $cwd ); - $raw = htmlspecialchars($file, ENT_XML1, 'UTF-8'); if (isset($_GET['c'])) $c = $_GET['c']; - if ( $c == 'on' ) { - $trans = [ " " => "&nbsp;" ]; - $lines = explode ( "\n" , $raw ); - foreach ($lines as $line) { - $inline = strtr($line , $trans); - $fc = substr($inline , 0 , 1); - if ( $fc == "+" ) { - echo "<div style='color:green;font-family:mono'>"; - } elseif ( $fc == "-" ) { - echo "<div style='color:red;font-family:mono'>"; - } elseif ( $fc == "@" ) { - echo "<div style='color:blue;font-family:mono'>"; - } else - echo "<div style='color:gray;font-family:mono'>"; - echo "$inline</div>\n"; - } - echo "<p></p>"; - } else - echo "<pre style='font-family:mono'>" , $raw , "</pre>"; + showdiff( GIT_DIR . 'en', $gitfile, $h2, $c ); } - - echo gen_date($DBLANG); + echo gen_date($DBLANG); break; case 'graph':

« previous php.doc.web (#2476) next »