Commit acb77f38 authored by Fabien Potencier's avatar Fabien Potencier

Merge remote branch 'igorw/escape'

* igorw/escape:
  [escape] html escaping shortcut
parents 8b91a722 7802575d
...@@ -244,6 +244,17 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe ...@@ -244,6 +244,17 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return new RedirectResponse($url, $status); 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. * Handles the request and deliver the response.
* *
......
...@@ -84,4 +84,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase ...@@ -84,4 +84,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$app->flush(); $app->flush();
$this->assertEquals(2, count($routes->all())); $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