Escape output. New ActionDoubleEntityDecode.

This commit is contained in:
Adam Backstrom 2012-08-21 21:37:36 -04:00
parent 1c435f5460
commit a58513cb59
2 changed files with 25 additions and 8 deletions

View File

@ -68,6 +68,21 @@ class ActionBase64Encode extends AbstractAction
} }
} }
class ActionDoubleEntityDecode extends AbstractAction
{
public function __construct( $value )
{
parent::__construct( $value );
$this->setContainer( new TextareaContainer );
$this->setFormatter( new EchoFormatter );
}
public function decode()
{
return html_entity_decode( html_entity_decode( $this->value, ENT_QUOTES, 'UTF-8' ), ENT_QUOTES, 'UTF-8' );
}
}
class ActionBase64Decode extends AbstractAction class ActionBase64Decode extends AbstractAction
{ {
public function __construct( $value ) public function __construct( $value )
@ -145,7 +160,7 @@ class TextareaContainer extends DivContainer
{ {
public function wrap( $contents ) public function wrap( $contents )
{ {
return parent::wrap( '<textarea>' . $contents . '</textarea>' ); return parent::wrap( '<textarea>' . htmlentities($contents) . '</textarea>' );
} }
} }

View File

@ -20,9 +20,10 @@ require_once 'functions.php';
<?php <?php
$action = null; $action = null;
$action_str = isset($_POST['action']) ? $_POST['action'] : null;
if( 'POST' === $_SERVER['REQUEST_METHOD'] ) { if( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
$class = "Action" . $_POST['action']; $class = "Action" . $action_str;
$action = new $class( $_POST['data'] ); $action = new $class( $_POST['data'] );
} }
@ -33,12 +34,13 @@ if( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
<form method="post"> <form method="post">
<textarea class="data" name="data"><?php if( $action ) echo $action->esc_raw(); ?></textarea><br> <textarea class="data" name="data"><?php if( $action ) echo $action->esc_raw(); ?></textarea><br>
<select name="action"> <select name="action">
<option value="QuotedPrintableDecode" <?php echo selected($_POST['action'], 'QuotedPrintableDecode'); ?>>quoted_printable_decode()</option> <option value="DoubleEntityDecode" <?php echo selected($action_str, 'DoubleEntityDecode'); ?>>html_entity_decode(html_entity_decode())</option>
<option value="Urlencode" <?php echo selected($_POST['action'], 'Urlencode'); ?>>urlencode()</option> <option value="QuotedPrintableDecode" <?php echo selected($action_str, 'QuotedPrintableDecode'); ?>>quoted_printable_decode()</option>
<option value="Urldecode"<?php echo selected($_POST['action'], 'Urldecode'); ?>>urldecode()</option> <option value="Urlencode" <?php echo selected($action_str, 'Urlencode'); ?>>urlencode()</option>
<option value="Unserialize"<?php echo selected($_POST['action'], 'Unserialize'); ?>>unserialize()</option> <option value="Urldecode"<?php echo selected($action_str, 'Urldecode'); ?>>urldecode()</option>
<option value="Base64Decode"<?php echo selected($_POST['action'], 'Base64Decode'); ?>>base64_decode()</option> <option value="Unserialize"<?php echo selected($action_str, 'Unserialize'); ?>>unserialize()</option>
<option value="Base64Encode"<?php echo selected($_POST['action'], 'Base64Encode'); ?>>base64_encode()</option> <option value="Base64Decode"<?php echo selected($action_str, 'Base64Decode'); ?>>base64_decode()</option>
<option value="Base64Encode"<?php echo selected($action_str, 'Base64Encode'); ?>>base64_encode()</option>
<select> <select>
<input type="submit"> <input type="submit">
</form> </form>