0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 23:28:42 +00:00

Implement native VarParser.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1604 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-03-05 05:03:01 +00:00
parent ff60e09780
commit 6cdcc8b8e1
3 changed files with 36 additions and 0 deletions

View File

@ -201,3 +201,4 @@ require 'HTMLPurifier/URIScheme/mailto.php';
require 'HTMLPurifier/URIScheme/news.php'; require 'HTMLPurifier/URIScheme/news.php';
require 'HTMLPurifier/URIScheme/nntp.php'; require 'HTMLPurifier/URIScheme/nntp.php';
require 'HTMLPurifier/VarParser/Flexible.php'; require 'HTMLPurifier/VarParser/Flexible.php';
require 'HTMLPurifier/VarParser/Native.php';

View File

@ -0,0 +1,25 @@
<?php
/**
* This variable parser uses PHP's internal code engine. Because it does
* this, it can represent all inputs; however, it is dangerous and cannot
* be used by users.
*/
class HTMLPurifier_VarParser_Native extends HTMLPurifier_VarParser
{
protected function parseImplementation($var, $type, $allow_null) {
return $this->evalExpression($var);
}
protected function evalExpression($expr) {
$var = null;
$result = eval("\$var = $expr;");
if ($result === false) {
throw new HTMLPurifier_VarParserException("Fatal error in evaluated code");
}
return $var;
}
}

View File

@ -0,0 +1,10 @@
<?php
class HTMLPurifier_VarParser_NativeTest extends HTMLPurifier_VarParserHarness
{
public function testValidateSimple() {
$this->assertValid('"foo\\\\"', 'string', 'foo\\');
}
}