Permalink
Browse files

Add elapsed time to minifyTextarea, better escaping

  • Loading branch information...
1 parent 7e08cff commit f680ac83e7b4ae03beff852ecd788e903a4b6ed9 @mrclay committed Nov 25, 2012
Showing with 10 additions and 7 deletions.
  1. +7 −4 min_extras/tools/minifyTextarea.php
  2. +3 −3 min_extras/tools/minifyUrl.php
@@ -17,7 +17,7 @@ function getPost($key) {
if ($base) {
$textIn = preg_replace(
'@(<head\\b[^>]*>)@i'
- ,'$1<base href="' . htmlentities($base) . '" />'
+ ,'$1<base href="' . htmlspecialchars($base, ENT_QUOTES, 'UTF-8') . '" />'
,$textIn
);
}
@@ -38,7 +38,7 @@ function getPost($key) {
,'contentType' => Minify::TYPE_HTML
));
} catch (Exception $e) {
- echo htmlspecialchars($e->getMessage());
+ echo htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
}
exit();
}
@@ -56,12 +56,14 @@ function getPost($key) {
}
$func = array($_POST['method'], 'minify');
$inOutBytes[0] = strlen($textIn);
+ $startTime = microtime(true);
try {
$textOut = call_user_func_array($func, $args);
} catch (Exception $e) {
- echo htmlspecialchars($e->getMessage());
+ echo htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
exit;
}
+ $elapsedTime = microtime(true) - $startTime;
$inOutBytes[1] = strlen($textOut);
}
@@ -74,14 +76,15 @@ function getPost($key) {
<table>
<tr><th>Bytes in</th><td>{$inOutBytes[0]} (after line endings normalized to <code>\\n</code>)</td></tr>
<tr><th>Bytes out</th><td>{$inOutBytes[1]} (reduced " . round(100 - (100 * $inOutBytes[1] / $inOutBytes[0])) . "%)</td></tr>
+ <tr><th>Time (s)</th><td>" . round($elapsedTime, 5) . "</td></tr>
</table>
";
}
?>
<form action="?2" method="post">
<p><label>Content<br><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php
if (isset($textOut)) {
- echo htmlspecialchars($textOut);
+ echo htmlspecialchars($textOut, ENT_QUOTES, 'UTF-8');
}
?></textarea></label></p>
<p>Minify with:
@@ -84,7 +84,7 @@ function sniffType($headers) {
&& ! preg_match('@<base\\b@i', $content)) {
$content = preg_replace(
'@(<head\\b[^>]*>)@i'
- ,'$1<base href="' . htmlentities($url) . '" />'
+ ,'$1<base href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" />'
,$content
);
}
@@ -119,7 +119,7 @@ function sniffType($headers) {
));
} catch (Exception $e) {
header('Content-Type: text/html;charset=utf-8');
- echo htmlspecialchars($e->getMessage());
+ echo htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
}
exit();
}
@@ -156,7 +156,7 @@ function sniffType($headers) {
<fieldset><legend>Retreival options</legend>
<ul>
- <li><label>User-Agent: <input type="text" name="ua" size="60" value="<?php echo htmlspecialchars($ua); ?>"></label>
+ <li><label>User-Agent: <input type="text" name="ua" size="60" value="<?php echo htmlspecialchars($ua, ENT_QUOTES, 'UTF-8'); ?>"></label>
<li><label>Cookie: <input type="text" name="cook" size="60"></label>
</ul>
</fieldset>

0 comments on commit f680ac8

Please sign in to comment.