Merge branch 'release/0.8.1'
This commit is contained in:
+5
-5
@@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
class Mustache {
|
class Mustache {
|
||||||
|
|
||||||
const VERSION = '0.8.0';
|
const VERSION = '0.8.1';
|
||||||
const SPEC_VERSION = '1.1.2';
|
const SPEC_VERSION = '1.1.2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,9 +90,9 @@ class Mustache {
|
|||||||
* // opening and closing delimiters, as an array or a space-separated string
|
* // opening and closing delimiters, as an array or a space-separated string
|
||||||
* 'delimiters' => '<% %>',
|
* 'delimiters' => '<% %>',
|
||||||
*
|
*
|
||||||
* // an array of pragmas to enable
|
* // an array of pragmas to enable/disable
|
||||||
* 'pragmas' => array(
|
* 'pragmas' => array(
|
||||||
* Mustache::PRAGMA_UNESCAPED
|
* Mustache::PRAGMA_UNESCAPED => true
|
||||||
* ),
|
* ),
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
@@ -132,8 +132,8 @@ class Mustache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['pragmas'])) {
|
if (isset($options['pragmas'])) {
|
||||||
foreach ($options['pragmas'] as $pragma_name) {
|
foreach ($options['pragmas'] as $pragma_name => $pragma_value) {
|
||||||
if (!in_array($pragma_name, $this->_pragmasImplemented)) {
|
if (!in_array($pragma_name, $this->_pragmasImplemented, true)) {
|
||||||
throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA);
|
throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once '../Mustache.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group mustache_injection
|
||||||
|
*/
|
||||||
|
class MustacheInjectionSectionTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
// interpolation
|
||||||
|
|
||||||
|
public function testInterpolationInjection() {
|
||||||
|
$data = array(
|
||||||
|
'a' => '{{ b }}',
|
||||||
|
'b' => 'FAIL'
|
||||||
|
);
|
||||||
|
$template = '{{ a }}';
|
||||||
|
$output = '{{ b }}';
|
||||||
|
$m = new Mustache();
|
||||||
|
$this->assertEquals($output, $m->render($template, $data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnescapedInterpolationInjection() {
|
||||||
|
$data = array(
|
||||||
|
'a' => '{{ b }}',
|
||||||
|
'b' => 'FAIL'
|
||||||
|
);
|
||||||
|
$template = '{{{ a }}}';
|
||||||
|
$output = '{{ b }}';
|
||||||
|
$m = new Mustache();
|
||||||
|
$this->assertEquals($output, $m->render($template, $data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sections
|
||||||
|
|
||||||
|
public function testSectionInjection() {
|
||||||
|
$data = array(
|
||||||
|
'a' => true,
|
||||||
|
'b' => '{{ c }}',
|
||||||
|
'c' => 'FAIL'
|
||||||
|
);
|
||||||
|
$template = '{{# a }}{{ b }}{{/ a }}';
|
||||||
|
$output = '{{ c }}';
|
||||||
|
$m = new Mustache();
|
||||||
|
$this->assertEquals($output, $m->render($template, $data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnescapedSectionInjection() {
|
||||||
|
$data = array(
|
||||||
|
'a' => true,
|
||||||
|
'b' => '{{ c }}',
|
||||||
|
'c' => 'FAIL'
|
||||||
|
);
|
||||||
|
$template = '{{# a }}{{{ b }}}{{/ a }}';
|
||||||
|
$output = '{{ c }}';
|
||||||
|
$m = new Mustache();
|
||||||
|
$this->assertEquals($output, $m->render($template, $data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// partials
|
||||||
|
|
||||||
|
public function testPartialInjection() {
|
||||||
|
$data = array(
|
||||||
|
'a' => '{{ b }}',
|
||||||
|
'b' => 'FAIL'
|
||||||
|
);
|
||||||
|
$template = '{{> partial }}';
|
||||||
|
$partials = array(
|
||||||
|
'partial' => '{{ a }}',
|
||||||
|
);
|
||||||
|
$output = '{{ b }}';
|
||||||
|
$m = new Mustache();
|
||||||
|
$this->assertEquals($output, $m->render($template, $data, $partials));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPartialUnescapedInjection() {
|
||||||
|
$data = array(
|
||||||
|
'a' => '{{ b }}',
|
||||||
|
'b' => 'FAIL'
|
||||||
|
);
|
||||||
|
$template = '{{> partial }}';
|
||||||
|
$partials = array(
|
||||||
|
'partial' => '{{{ a }}}',
|
||||||
|
);
|
||||||
|
$output = '{{ b }}';
|
||||||
|
$m = new Mustache();
|
||||||
|
$this->assertEquals($output, $m->render($template, $data, $partials));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// lambdas
|
||||||
|
|
||||||
|
public function testLambdaInterpolationInjection() {
|
||||||
|
$data = array(
|
||||||
|
'a' => array($this, 'interpolationLambda'),
|
||||||
|
'b' => '{{ c }}',
|
||||||
|
'c' => 'FAIL'
|
||||||
|
);
|
||||||
|
$template = '{{ a }}';
|
||||||
|
$output = '{{ c }}';
|
||||||
|
$m = new Mustache();
|
||||||
|
$this->assertEquals($output, $m->render($template, $data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function interpolationLambda() {
|
||||||
|
return '{{ b }}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLambdaSectionInjection() {
|
||||||
|
$data = array(
|
||||||
|
'a' => array($this, 'sectionLambda'),
|
||||||
|
'b' => '{{ c }}',
|
||||||
|
'c' => 'FAIL'
|
||||||
|
);
|
||||||
|
$template = '{{# a }}b{{/ a }}';
|
||||||
|
$output = '{{ c }}';
|
||||||
|
$m = new Mustache();
|
||||||
|
$this->assertEquals($output, $m->render($template, $data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sectionLambda($content) {
|
||||||
|
return '{{ ' . $content . ' }}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -94,21 +94,21 @@ class MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
array(
|
array(
|
||||||
'charset' => 'UTF-8',
|
'charset' => 'UTF-8',
|
||||||
'delimiters' => '<< >>',
|
'delimiters' => '<< >>',
|
||||||
'pragmas' => array(Mustache::PRAGMA_UNESCAPED)
|
'pragmas' => array(Mustache::PRAGMA_UNESCAPED => true)
|
||||||
),
|
),
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
array('<<', '>>'),
|
array('<<', '>>'),
|
||||||
array(Mustache::PRAGMA_UNESCAPED),
|
array(Mustache::PRAGMA_UNESCAPED => true),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'charset' => 'cp866',
|
'charset' => 'cp866',
|
||||||
'delimiters' => array('[[[[', ']]]]'),
|
'delimiters' => array('[[[[', ']]]]'),
|
||||||
'pragmas' => array(Mustache::PRAGMA_UNESCAPED)
|
'pragmas' => array(Mustache::PRAGMA_UNESCAPED => true)
|
||||||
),
|
),
|
||||||
'cp866',
|
'cp866',
|
||||||
array('[[[[', ']]]]'),
|
array('[[[[', ']]]]'),
|
||||||
array(Mustache::PRAGMA_UNESCAPED),
|
array(Mustache::PRAGMA_UNESCAPED => true),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ class MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
* @expectedException MustacheException
|
* @expectedException MustacheException
|
||||||
*/
|
*/
|
||||||
public function testConstructorInvalidPragmaOptionsThrowExceptions() {
|
public function testConstructorInvalidPragmaOptionsThrowExceptions() {
|
||||||
$mustache = new Mustache(null, null, null, array('pragmas' => array('banana phone')));
|
$mustache = new Mustache(null, null, null, array('pragmas' => array('banana phone' => true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,7 +195,7 @@ class MustacheTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('Charlie Chaplin', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin')));
|
$this->assertEquals('Charlie Chaplin', $m->render(null, array('first_name' => 'Charlie', 'last_name' => 'Chaplin')));
|
||||||
$this->assertEquals('Zappa, Frank', $m->render('{{last_name}}, {{first_name}}', array('first_name' => 'Frank', 'last_name' => 'Zappa')));
|
$this->assertEquals('Zappa, Frank', $m->render('{{last_name}}, {{first_name}}', array('first_name' => 'Frank', 'last_name' => 'Zappa')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group interpolation
|
* @group interpolation
|
||||||
* @dataProvider interpolationData
|
* @dataProvider interpolationData
|
||||||
|
|||||||
Reference in New Issue
Block a user