Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100029060
PhutilcsprintfTestCase.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
Mon, Jan 27, 19:17
Size
1 KB
Mime Type
text/x-php
Expires
Wed, Jan 29, 19:17 (2 d)
Engine
blob
Format
Raw Data
Handle
23890001
Attached To
rPHU libphutil
PhutilcsprintfTestCase.php
View Options
<?php
final
class
PhutilcsprintfTestCase
extends
ArcanistTestCase
{
public
function
testPasswords
()
{
// Normal "%s" doesn't do anything special.
$command
=
csprintf
(
'echo %s'
,
'hunter2trustno1'
);
$this
->
assertEqual
(
true
,
strpos
(
$command
,
'hunter2trustno1'
)
!==
false
);
// "%P" takes a PhutilOpaqueEnvelope.
$caught
=
null
;
try
{
csprintf
(
'echo %P'
,
'hunter2trustno1'
);
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
$this
->
assertEqual
(
true
,
(
$caught
instanceof
Exception
));
// "%P" masks the provided value.
$command
=
csprintf
(
'echo %P'
,
new
PhutilOpaqueEnvelope
(
'hunter2trustno1'
));
$this
->
assertEqual
(
false
,
strpos
(
$command
,
'hunter2trustno1'
));
// Executing the command works as expected.
list
(
$out
)
=
execx
(
'%C'
,
$command
);
$this
->
assertEqual
(
true
,
strpos
(
$out
,
'hunter2trustno1'
)
!==
false
);
// Escaping should be robust even when used to escape commands which take
// other commands.
if
(!
phutil_is_windows
())
{
list
(
$out
)
=
execx
(
'sh -c %s'
,
csprintf
(
'sh -c %s'
,
csprintf
(
'sh -c %s'
,
csprintf
(
'echo %P'
,
new
PhutilOpaqueEnvelope
(
'!@#$%^&*()'
)))));
$this
->
assertEqual
(
true
,
strpos
(
$out
,
'!@#$%^&*()'
)
!==
false
);
}
}
}
Event Timeline
Log In to Comment