Commit 7802575d authored by Igor Wiedler's avatar Igor Wiedler

[escape] html escaping shortcut

parent 29242300
......@@ -250,6 +250,17 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return new RedirectResponse($url, $status);
}
/**
* Escapes a text for HTML.
*
* @param string $text The input text to be escaped
* @return string Escaped text
*/
public function escape($text)
{
return htmlspecialchars($text, ENT_COMPAT, 'UTF-8');
}
/**
* Handles the request and deliver the response.
*
......
......@@ -84,4 +84,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$app->flush();
$this->assertEquals(2, count($routes->all()));
}
/**
* @dataProvider escapeProvider
*/
public function testEscape($expected, $text)
{
$app = new Application();
$this->assertEquals($expected, $app->escape($text));
}
public function escapeProvider()
{
return array(
array('&lt;', '<'),
array('&gt;', '>'),
array('&quot;', '"'),
array("'", "'"),
array('abc', 'abc'),
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment