Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94112866
PhutilMarkupTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Dec 4, 00:38
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Dec 6, 00:38 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22737855
Attached To
rPHU libphutil
PhutilMarkupTestCase.php
View Options
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group testcase
*/
class
PhutilMarkupTestCase
extends
ArcanistPhutilTestCase
{
public
function
testTagDefaults
()
{
$this
->
assertEqual
(
phutil_render_tag
(
'x'
),
phutil_render_tag
(
'x'
,
array
()));
$this
->
assertEqual
(
phutil_render_tag
(
'x'
,
array
()),
phutil_render_tag
(
'x'
,
array
(),
null
));
}
public
function
testTagEmpty
()
{
$this
->
assertEqual
(
'<x />'
,
phutil_render_tag
(
'x'
,
array
(),
null
));
$this
->
assertEqual
(
'<x></x>'
,
phutil_render_tag
(
'x'
,
array
(),
''
));
}
public
function
testTagBasics
()
{
$this
->
assertEqual
(
'<x />'
,
phutil_render_tag
(
'x'
));
$this
->
assertEqual
(
'<x>y</x>'
,
phutil_render_tag
(
'x'
,
array
(),
'y'
));
}
public
function
testTagAttributes
()
{
$this
->
assertEqual
(
'<x u="v">y</x>'
,
phutil_render_tag
(
'x'
,
array
(
'u'
=>
'v'
),
'y'
));
$this
->
assertEqual
(
'<x u="v" />'
,
phutil_render_tag
(
'x'
,
array
(
'u'
=>
'v'
)));
}
public
function
testTagEscapes
()
{
$this
->
assertEqual
(
'<x u="<" />'
,
phutil_render_tag
(
'x'
,
array
(
'u'
=>
'<'
)));
$this
->
assertEqual
(
'<x><y /></x>'
,
phutil_render_tag
(
'x'
,
array
(),
phutil_render_tag
(
'y'
)));
}
public
function
testTagJavascriptProtocolRejection
()
{
$hrefs
=
array
(
'javascript:alert(1)'
=>
true
,
'JAVASCRIPT:alert(1)'
=>
true
,
' javascript:alert(1)'
=>
true
,
'/'
=>
false
,
'/path/to/stuff/'
=>
false
,
''
=>
false
,
'http://example.com/'
=>
false
,
'#'
=>
false
,
);
foreach
(
array
(
true
,
false
)
as
$use_uri
)
{
foreach
(
$hrefs
as
$href
=>
$expect
)
{
if
(
$use_uri
)
{
$href
=
new
PhutilURI
(
$href
);
}
$caught
=
null
;
try
{
phutil_render_tag
(
'a'
,
array
(
'href'
=>
$href
),
'click for candy'
);
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
$this
->
assertEqual
(
$expect
,
$caught
instanceof
Exception
,
"Rejected href: {$href}"
);
}
}
}
}
Event Timeline
Log In to Comment