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:
parent
ff60e09780
commit
6cdcc8b8e1
@ -201,3 +201,4 @@ require 'HTMLPurifier/URIScheme/mailto.php';
|
||||
require 'HTMLPurifier/URIScheme/news.php';
|
||||
require 'HTMLPurifier/URIScheme/nntp.php';
|
||||
require 'HTMLPurifier/VarParser/Flexible.php';
|
||||
require 'HTMLPurifier/VarParser/Native.php';
|
||||
|
25
library/HTMLPurifier/VarParser/Native.php
Normal file
25
library/HTMLPurifier/VarParser/Native.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
10
tests/HTMLPurifier/VarParser/NativeTest.php
Normal file
10
tests/HTMLPurifier/VarParser/NativeTest.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_VarParser_NativeTest extends HTMLPurifier_VarParserHarness
|
||||
{
|
||||
|
||||
public function testValidateSimple() {
|
||||
$this->assertValid('"foo\\\\"', 'string', 'foo\\');
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user