Skip to content

Commit

Permalink
htmlentities func
Browse files Browse the repository at this point in the history
  • Loading branch information
zzgab committed Sep 10, 2015
1 parent 2b3cc69 commit 14b8ea8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/figdice/classes/functions/Function_htmlentities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @author Gabriel Zerbib <gabriel@figdice.org>
* @copyright 2004-2015, Gabriel Zerbib.
* @version 2.1.2
* @package FigDice
*
* This file is part of FigDice.
* http://figdice.org/
*/

namespace figdice\classes\functions;

use \figdice\FigFunction;
use \figdice\classes\ViewElementTag;
use \figdice\exceptions\FunctionCallException;

class Function_htmlentities implements FigFunction {
public function __construct() {
}

/**
* Function's arguments:
* string to escape
*
* @param ViewElement $viewElement
* @param integer $arity
* @param array $arguments
*/
public function evaluate(ViewElementTag $viewElement, $arity, $arguments) {
if($arity != 1) {
throw new FunctionCallException(
'htmlentities',
'Expects exactly 1 argument.',
$viewElement->getCurrentFile()->getFilename(),
$viewElement->getLineNumber()
);
}

$string = $arguments[0];
return htmlentities($string);
}
}
10 changes: 10 additions & 0 deletions test/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public function testSpecialHTMLCharacterAfterFilter()
$view->mount('data', '<TAG>');
$this->assertEquals('<test><span>&lt;TAG&gt;</span></test>', $view->render());
}

public function testHtmlEntitiesBuiltin()
{
$view = new View();
$view->loadString(
'<test><span fig:text="htmlentities(/data)"/></test>'
);
$view->mount('data', '<TAG>');
$this->assertEquals('<test><span>&lt;TAG&gt;</span></test>', $view->render());
}
}

class EscapeHtmlFilter implements Filter
Expand Down

0 comments on commit 14b8ea8

Please sign in to comment.