Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
syna
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Flori
syna
Commits
e5f0ef4c
Unverified
Commit
e5f0ef4c
authored
6 years ago
by
Thomas Flori
Browse files
Options
Downloads
Patches
Plain Diff
test escaping in views
parent
44a06823
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/View.php
+0
-4
0 additions, 4 deletions
src/View.php
tests/View/EscapingTest.php
+53
-0
53 additions, 0 deletions
tests/View/EscapingTest.php
with
53 additions
and
4 deletions
src/View.php
+
0
−
4
View file @
e5f0ef4c
...
...
@@ -276,10 +276,6 @@ class View
$string
=
$this
->
batch
(
$string
,
$functions
);
}
if
(
!
is_string
(
$string
))
{
throw
new
\LogicException
(
'Only strings can be used for escaping'
);
}
return
htmlspecialchars
(
$string
,
$flags
,
'UTF-8'
);
}
}
This diff is collapsed.
Click to expand it.
tests/View/EscapingTest.php
0 → 100644
+
53
−
0
View file @
e5f0ef4c
<?php
namespace
Syna\Test\View
;
use
Syna\Factory
;
use
Syna\Test\TestCase
;
use
Mockery
as
m
;
use
Syna\ViewLocator
;
class
EscapingTest
extends
TestCase
{
/** @var m\Mock|Factory */
protected
$factory
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
factory
=
m
::
mock
(
Factory
::
class
,
[
new
ViewLocator
(
$this
->
templatePath
)])
->
makePartial
();
}
/** @test */
public
function
usingEscapeMethod
()
{
$this
->
createTemplate
(
'escape.php'
,
'<?= $v->escape("<p class=\\"intro\\">Lorem ipsum</p>") ?>'
);
$view
=
$this
->
factory
->
view
(
'escape'
);
$result
=
$view
->
render
();
self
::
assertSame
(
'<p class="intro">Lorem ipsum</p>'
,
$result
);
}
/** @test */
public
function
usingDollarE
()
{
$this
->
createTemplate
(
'escape.php'
,
'<?= $e("<p class=\\"intro\\">Lorem ipsum</p>") ?>'
);
$view
=
$this
->
factory
->
view
(
'escape'
);
$result
=
$view
->
render
();
self
::
assertSame
(
'<p class="intro">Lorem ipsum</p>'
,
$result
);
}
/** @test */
public
function
batchProcessingBeforeEscaping
()
{
$this
->
createTemplate
(
'escape.php'
,
'<?= $e($title, "strtoupper") ?>'
);
$view
=
$this
->
factory
->
view
(
'escape'
);
$result
=
$view
->
render
([
'title'
=>
'Lorem & Ipsum'
]);
self
::
assertSame
(
'LOREM & IPSUM'
,
$result
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment