Skip to content
This repository has been archived by the owner on Sep 5, 2018. It is now read-only.

Commit

Permalink
- changed the way values are passed as arguments to calls to address …
Browse files Browse the repository at this point in the history
…referencing issues
  • Loading branch information
fieryprophet committed Oct 27, 2014
1 parent 5e62f40 commit db9ca30
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 22 deletions.
2 changes: 1 addition & 1 deletion MANUAL.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h3>1 - About PHPSandbox &amp; PHPSandbox Toolkit</h3>
</a>
<br/>
<h1 style="margin: 0;">
PHPSandbox Toolkit 1.3.8
PHPSandbox Toolkit 1.3.9
</h1>
<br/>
<strong>Developed by: </strong> <a href="http://www.fieryprophet.com" target="_blank">Elijah Horton</a>
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"phpdocumentor/phpdocumentor": "v2.3.0"
},
"autoload": {
"files": [ "src/functions.php" ],
"psr-4": { "PHPSandbox\\": "src/" }
}
}
2 changes: 1 addition & 1 deletion src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.8
* @version 1.3.9
*/
class Error extends \Exception {
/* START ERROR CODES */
Expand Down
16 changes: 1 addition & 15 deletions src/PHPSandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.8
* @version 1.3.9
*/
class PHPSandbox implements \IteratorAggregate {
/**
Expand Down Expand Up @@ -1977,20 +1977,6 @@ public function _func_num_args(array $arguments = array()){
}
return $count > 0 ? $count : 0;
}
/** Wrap output value in SandboxString
*
* @param mixed $value Value to wrap
*
* @return mixed|SandboxedString Returns the wrapped value
*/
public function _wrap($value){
if(is_object($value) && method_exists($value, '__toString')){
return $this->_wrap(strval($value));
} else if(is_string($value) && is_callable($value)){
return new SandboxedString($value, $this);
}
return $value;
}
/** Get PHPSandbox redefined var_dump
*
* @return array Returns the redefined var_dump
Expand Down
2 changes: 1 addition & 1 deletion src/SandboxWhitelistVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.8
* @version 1.3.9
*/
class SandboxWhitelistVisitor extends \PHPParser_NodeVisitorAbstract {
/** The PHPSandbox instance to check against
Expand Down
2 changes: 1 addition & 1 deletion src/SandboxedString.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.8
* @version 1.3.9
*/
class SandboxedString implements \ArrayAccess, \IteratorAggregate {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/ValidatorVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.8
* @version 1.3.9
*/
class ValidatorVisitor extends \PHPParser_NodeVisitorAbstract {
/** The PHPSandbox instance to check against
Expand All @@ -39,7 +39,7 @@ public function __construct(PHPSandbox $sandbox){
*/
public function leaveNode(\PHPParser_Node $node){
if($node instanceof \PHPParser_Node_Arg){
return new \PHPParser_Node_Expr_MethodCall(new \PHPParser_Node_Expr_StaticCall(new \PHPParser_Node_Name_FullyQualified("PHPSandbox\\PHPSandbox"), 'getSandbox', array(new \PHPParser_Node_Scalar_String($this->sandbox->name))), '_wrap', array($node), $node->getAttributes());
return new \PHPParser_Node_Expr_FuncCall(new \PHPParser_Node_Name_FullyQualified(($node->value instanceof \PHPParser_Node_Expr_Variable) ? 'PHPSandbox\\wrapByRef' : 'PHPSandbox\\wrap'), array($node, new \PHPParser_Node_Expr_StaticCall(new \PHPParser_Node_Name_FullyQualified("PHPSandbox\\PHPSandbox"), 'getSandbox', array(new \PHPParser_Node_Scalar_String($this->sandbox->name)))), $node->getAttributes());
} else if($node instanceof \PHPParser_Node_Stmt_InlineHTML){
if(!$this->sandbox->allow_escaping){
$this->sandbox->validation_error("Sandboxed code attempted to escape to HTML!", Error::ESCAPE_ERROR, $node);
Expand Down
2 changes: 1 addition & 1 deletion src/WhitelistVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.8
* @version 1.3.9
*/
class WhitelistVisitor extends \PHPParser_NodeVisitorAbstract {
/** The PHPSandbox instance to check against
Expand Down
36 changes: 36 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace PHPSandbox;

/** Wrap output value in SandboxString
*
* @param mixed $value Value to wrap
* @param PHPSandbox $sandbox Sandbox instance of calling code
*
* @return mixed|SandboxedString Returns the wrapped value
*/
function wrap($value, $sandbox){
if(!($value instanceof SandboxedString) && is_object($value) && method_exists($value, '__toString')){
$strval = $value->__toString();
return is_callable($strval) ? new SandboxedString($strval, $sandbox) : $value;
} else if(is_string($value) && is_callable($value)){
return new SandboxedString($value, $sandbox);
}
return $value;
}

/** Wrap output value in SandboxString by reference
*
* @param mixed $value Value to wrap
* @param PHPSandbox $sandbox Sandbox instance of calling code
*
* @return mixed|SandboxedString Returns the wrapped value
*/
function &wrapByRef(&$value, $sandbox){
if(!($value instanceof SandboxedString) && is_object($value) && method_exists($value, '__toString')){
$strval = $value->__toString();
return is_callable($strval) ? new SandboxedString($strval, $sandbox) : $value;
} else if(is_string($value) && is_callable($value)){
return new SandboxedString($value, $sandbox);
}
return $value;
}

0 comments on commit db9ca30

Please sign in to comment.