Move side by side diff html escaping to view layer
Move side by side diff html escaping to view layer

--- a/css/gitphp.css
+++ b/css/gitphp.css
@@ -49,7 +49,7 @@
 /*
  * Diff display
  */
-div.pre { 
+.pre { 
 	white-space: pre; 
 }
 

--- a/include/controller/Controller_Sidediff.class.php
+++ b/include/controller/Controller_Sidediff.class.php
@@ -9,18 +9,6 @@
  * @subpackage Controller
  */
 
-/**
- * private little helper
- */
-function toH($in) {
-	if(!$in || strlen($in) == 0) {
-		return "&nbsp";
-	} else {
-		$in = htmlentities($in);
-		$in = str_replace(" ", " ", $in);
-		return $in;
-	}
-}
 
 /**
  * Blobdiff controller class
@@ -204,7 +192,7 @@
 		$idx = 0;
 		foreach($diffs as $d) {
 			while($idx+1 < $d['line']) {
-				$h = toH($blob[$idx]);
+				$h = $blob[$idx];
 				$output[] = array(' ', $h, $h);
 				$idx ++;
 			}
@@ -220,14 +208,14 @@
 			for($i = 0; $i < count($d['left']) || $i < count($d['right']); $i++) {
 				$left = $i < count($d['left']) ? $d['left'][$i] : FALSE;
 				$right = $i < count($d['right']) ? $d['right'][$i] : FALSE;
-				$output[] = array($mode, toH($left), toH($right));
+				$output[] = array($mode, $left, $right);
 			}
 
 			$idx += count($d['left']);
 		}
 
 		while($idx < count($blob)) {
-			$h = toH($blob[$idx]);
+			$h = $blob[$idx];
 			$output[] = array(' ', $h, $h);
 			$idx ++;
 		}

--- a/templates/sidebyside.tpl
+++ b/templates/sidebyside.tpl
@@ -24,11 +24,11 @@
      {t}blob{/t}:<a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=blob&amp;h={$blobparent->GetHash()}&amp;hb={$commit->GetHash()}&amp;f={$file}">{if $file}a/{$file}{else}{$blobparent->GetHash()}{/if}</a> -&gt; {t}blob{/t}:<a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&amp;a=blob&amp;h={$blob->GetHash()}&amp;hb={$commit->GetHash()}&amp;f={$file}">{if $file}b/{$file}{else}{$blob->GetHash()}{/if}</a>
    </div>
    {* Display the sidebysidediff *}
-   <table class="diffTable">
+   <table class="diffTable pre">
    {foreach from=$diffdata item=lineinfo}
      <tr>
-       <td class="diff{$lineinfo[0]} diff-left">{$lineinfo[1]}</td>
-       <td class="diff{$lineinfo[0]}">{$lineinfo[2]}</td>
+       <td class="diff{$lineinfo[0]} diff-left">{$lineinfo[1]|escape}</td>
+       <td class="diff{$lineinfo[0]}">{$lineinfo[2]|escape}</td>
      </tr>
    {/foreach}
    </table>

comments