Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
acb77f38
Commit
acb77f38
authored
Apr 14, 2011
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote branch 'igorw/escape'
* igorw/escape: [escape] html escaping shortcut
parents
8b91a722
7802575d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
src/Silex/Application.php
src/Silex/Application.php
+11
-0
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+21
-0
No files found.
src/Silex/Application.php
View file @
acb77f38
...
@@ -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.
*
*
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
acb77f38
...
@@ -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
(
'<'
,
'<'
),
array
(
'>'
,
'>'
),
array
(
'"'
,
'"'
),
array
(
"'"
,
"'"
),
array
(
'abc'
,
'abc'
),
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment