Skip to content

Instantly share code, notes, and snippets.

@Rayne
Created May 8, 2014 13:58
Show Gist options
  • Save Rayne/837b7e9eefef969eaaab to your computer and use it in GitHub Desktop.
Save Rayne/837b7e9eefef969eaaab to your computer and use it in GitHub Desktop.
F3 Escaping Problem
<?php
$root = dirname(__DIR__) . '/';
/** @var $fw \Base */
$fw = require $root . 'vendor/bcosca/fatfree/lib/base.php';
$fw->set('CACHE', 'folder=' . __DIR__ . '/tmp/cache/');
$fw->set('CASELESS', false);
$fw->set('DEBUG', 2);
$fw->set('TEMP', __DIR__ . '/tmp/');
$fw->set('UI', __DIR__ . '/');
$fw->set('value', '<p><span style="color:red;">R</span><span style="color:green;">G</span><span style="color:blue;">B</span> when not escaped</p>');
// Escapes `value` and stores the result as `value_escaped`.
$value_escaped = Template::instance()->render('value.html');
$fw->set('value_escaped', $value_escaped);
// Prints `value_escaped` as RAW text.
// Expected: escaped `value`.
// Result: non-escaped `value`.
$value_result = Template::instance()->render('master.html');
echo '<h1>Expected (escaped `value`)</h1>';
echo $value_escaped;
echo '<h1>Result (non-escaped `value` instead of escaped `value_escaped`)</h1>';
echo $value_result;
{{ @value_escaped | raw }}
<h1>Expected (escaped `value`)</h1>&lt;p&gt;&lt;span style=&quot;color:red;&quot;&gt;R&lt;/span&gt;&lt;span style=&quot;color:green;&quot;&gt;G&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;B&lt;/span&gt; when not escaped&lt;/p&gt;<h1>Result (non-escaped `value` instead of escaped `value_escaped`)</h1><p><span style="color:red;">R</span><span style="color:green;">G</span><span style="color:blue;">B</span> when not escaped</p>
{{ @value }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment