Skip to content

Commit

Permalink
Fix for #42
Browse files Browse the repository at this point in the history
Signed-off-by: Shivam Dixit <[email protected]>
  • Loading branch information
shivamdixit committed Aug 16, 2014
1 parent 5d593f4 commit 54300fc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/control/mode/single/challenges/__catch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class SingleModeController extends JCatchControl
{
private $indentSize;

public function Handle($request)
{
// This gives complete request path
Expand Down Expand Up @@ -57,8 +59,11 @@ public function Handle($request)
$sourceCodeToDisplay = "";
if ($secureCoding['status'] === true) {
$sourceCode = file($absolutePath."index.php");
$firstLine = $sourceCode[$secureCoding['start']];
$this->indentSize = strlen($firstLine) - strlen(ltrim($firstLine));

for ($i = $secureCoding['start']; $i < $secureCoding['end']; $i++) {
$sourceCodeToDisplay .= (trim($sourceCode[$i])."\n");
$sourceCodeToDisplay .= ($this->removeWhitespaces($sourceCode[$i])."\n");
}
$this->sourceCode = $sourceCodeToDisplay;
}
Expand Down Expand Up @@ -98,4 +103,16 @@ private function getRelativePath($request)
$presentDir = basename(dirname(__FILE__));
return substr($request, (strpos($request, $presentDir) + strlen($presentDir) + 1));
}

/**
* Remove whitespaces to indent the code properly
*
* @param $line String which is to be trimmed
*
* @return string trimmed result
*/
private function removeWhitespaces($line)
{
return rtrim(substr($line, $this->indentSize));
}
}

0 comments on commit 54300fc

Please sign in to comment.