Skip to content

Commit 360ab1d

Browse files
committed
Port changes from htmLawed 1.1.22
1 parent 615b143 commit 360ab1d

5 files changed

Lines changed: 78 additions & 55 deletions

File tree

src/htmLawed/htmLawed.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
htmLawed 1.1.20, 9 June 2015
4+
htmLawed 1.1.22, 5 March 2016
55
Copyright Santosh Patnaik
66
Dual licensed with LGPL 3 and GPL 2+
77
A PHP Labware internal utility; www.bioinformatics.org/phplabware/internal_utilities/htmLawed
@@ -147,10 +147,15 @@ function htmLawed($t, $C = 1, $S = array()) {
147147
// eof
148148
}
149149

150-
function hl_attrval($t, $p) {
150+
function hl_attrval($a, $t, $p) {
151151
// check attr val against $S
152+
static $ma = array('accesskey', 'class', 'rel');
153+
$s = in_array($a, $ma) ? ' ' : '';
154+
$r = array();
155+
$t = !empty($s) ? explode($s, $t) : array($t);
156+
foreach ($t as $tk => $tv) {
152157
$o = 1;
153-
$l = strlen($t);
158+
$l = strlen($tv);
154159
foreach ($p as $k => $v) {
155160
switch ($k) {
156161
case 'maxlen':
@@ -164,29 +169,29 @@ function hl_attrval($t, $p) {
164169
}
165170
break;
166171
case 'maxval':
167-
if ((float)($t) > $v) {
172+
if ((float)($tv) > $v) {
168173
$o = 0;
169174
}
170175
break;
171176
case 'minval':
172-
if ((float)($t) < $v) {
177+
if ((float)($tv) < $v) {
173178
$o = 0;
174179
}
175180
break;
176181
case 'match':
177-
if (!preg_match($v, $t)) {
182+
if (!preg_match($v, $tv)) {
178183
$o = 0;
179184
}
180185
break;
181186
case 'nomatch':
182-
if (preg_match($v, $t)) {
187+
if (preg_match($v, $tv)) {
183188
$o = 0;
184189
}
185190
break;
186191
case 'oneof':
187192
$m = 0;
188193
foreach (explode('|', $v) as $n) {
189-
if ($t == $n) {
194+
if ($tv == $n) {
190195
$m = 1;
191196
break;
192197
}
@@ -196,7 +201,7 @@ function hl_attrval($t, $p) {
196201
case 'noneof':
197202
$m = 1;
198203
foreach (explode('|', $v) as $n) {
199-
if ($t == $n) {
204+
if ($tv == $n) {
200205
$m = 0;
201206
break;
202207
}
@@ -210,7 +215,12 @@ function hl_attrval($t, $p) {
210215
break;
211216
}
212217
}
213-
return ($o ? $t : (isset($p['default']) ? $p['default'] : 0));
218+
if ($o) {
219+
$r[] = $tv;
220+
}
221+
}
222+
$r = implode($s, $r);
223+
return (isset($r[0]) ? $r : (isset($p['default']) ? $p['default'] : 0));
214224
// eof
215225
}
216226

@@ -681,7 +691,6 @@ function hl_tag($t) {
681691
if (!empty($m[1])) {
682692
return (!isset($eE[$e]) ? (empty($C['hook_tag']) ? "</$e>" : $C['hook_tag']($e)) : (($C['keep_bad']) % 2 ? str_replace(array('<', '>'), array('&lt;', '&gt;'), $t) : ''));
683693
}
684-
685694
// open tag & attr
686695
static $aN = array('abbr' => array('td' => 1, 'th' => 1), 'accept-charset' => array('form' => 1), 'accept' => array('form' => 1, 'input' => 1), 'accesskey' => array('a' => 1, 'area' => 1, 'button' => 1, 'input' => 1, 'label' => 1, 'legend' => 1, 'textarea' => 1), 'action' => array('form' => 1), 'align' => array('caption' => 1, 'embed' => 1, 'applet' => 1, 'iframe' => 1, 'img' => 1, 'input' => 1, 'object' => 1, 'legend' => 1, 'table' => 1, 'hr' => 1, 'div' => 1, 'h1' => 1, 'h2' => 1, 'h3' => 1, 'h4' => 1, 'h5' => 1, 'h6' => 1, 'p' => 1, 'col' => 1, 'colgroup' => 1, 'tbody' => 1, 'td' => 1, 'tfoot' => 1, 'th' => 1, 'thead' => 1, 'tr' => 1), 'allowfullscreen' => array('iframe' => 1), 'alt' => array('applet' => 1, 'area' => 1, 'img' => 1, 'input' => 1), 'archive' => array('applet' => 1, 'object' => 1), 'axis' => array('td' => 1, 'th' => 1), 'bgcolor' => array('embed' => 1, 'table' => 1, 'tr' => 1, 'td' => 1, 'th' => 1), 'border' => array('table' => 1, 'img' => 1, 'object' => 1), 'bordercolor' => array('table' => 1, 'td' => 1, 'tr' => 1), 'cellpadding' => array('table' => 1), 'cellspacing' => array('table' => 1), 'char' => array('col' => 1, 'colgroup' => 1, 'tbody' => 1, 'td' => 1, 'tfoot' => 1, 'th' => 1, 'thead' => 1, 'tr' => 1), 'charoff' => array('col' => 1, 'colgroup' => 1, 'tbody' => 1, 'td' => 1, 'tfoot' => 1, 'th' => 1, 'thead' => 1, 'tr' => 1), 'charset' => array('a' => 1, 'script' => 1), 'checked' => array('input' => 1), 'cite' => array('blockquote' => 1, 'q' => 1, 'del' => 1, 'ins' => 1), 'classid' => array('object' => 1), 'clear' => array('br' => 1), 'code' => array('applet' => 1), 'codebase' => array('object' => 1, 'applet' => 1), 'codetype' => array('object' => 1), 'color' => array('font' => 1), 'cols' => array('textarea' => 1), 'colspan' => array('td' => 1, 'th' => 1), 'compact' => array('dir' => 1, 'dl' => 1, 'menu' => 1, 'ol' => 1, 'ul' => 1), 'coords' => array('area' => 1, 'a' => 1), 'data' => array('object' => 1), 'datetime' => array('del' => 1, 'ins' => 1), 'declare' => array('object' => 1), 'defer' => array('script' => 1), 'dir' => array('bdo' => 1), 'disabled' => array('button' => 1, 'input' => 1, 'optgroup' => 1, 'option' => 1, 'select' => 1, 'textarea' => 1), 'enctype' => array('form' => 1), 'face' => array('font' => 1), 'flashvars' => array('embed' => 1), 'for' => array('label' => 1), 'frame' => array('table' => 1), 'frameborder' => array('iframe' => 1), 'headers' => array('td' => 1, 'th' => 1), 'height' => array('embed' => 1, 'iframe' => 1, 'td' => 1, 'th' => 1, 'img' => 1, 'object' => 1, 'applet' => 1), 'href' => array('a' => 1, 'area' => 1), 'hreflang' => array('a' => 1), 'hspace' => array('applet' => 1, 'img' => 1, 'object' => 1), 'ismap' => array('img' => 1, 'input' => 1), 'label' => array('option' => 1, 'optgroup' => 1), 'language' => array('script' => 1), 'longdesc' => array('img' => 1, 'iframe' => 1), 'marginheight' => array('iframe' => 1), 'marginwidth' => array('iframe' => 1), 'maxlength' => array('input' => 1), 'method' => array('form' => 1), 'model' => array('embed' => 1), 'multiple' => array('select' => 1), 'name' => array('button' => 1, 'embed' => 1, 'textarea' => 1, 'applet' => 1, 'select' => 1, 'form' => 1, 'iframe' => 1, 'img' => 1, 'a' => 1, 'input' => 1, 'object' => 1, 'map' => 1, 'param' => 1), 'nohref' => array('area' => 1), 'noshade' => array('hr' => 1), 'nowrap' => array('td' => 1, 'th' => 1), 'object' => array('applet' => 1), 'onblur' => array('a' => 1, 'area' => 1, 'button' => 1, 'input' => 1, 'label' => 1, 'select' => 1, 'textarea' => 1), 'onchange' => array('input' => 1, 'select' => 1, 'textarea' => 1), 'onfocus' => array('a' => 1, 'area' => 1, 'button' => 1, 'input' => 1, 'label' => 1, 'select' => 1, 'textarea' => 1), 'onreset' => array('form' => 1), 'onselect' => array('input' => 1, 'textarea' => 1), 'onsubmit' => array('form' => 1), 'pluginspage' => array('embed' => 1), 'pluginurl' => array('embed' => 1), 'prompt' => array('isindex' => 1), 'readonly' => array('textarea' => 1, 'input' => 1), 'rel' => array('a' => 1), 'rev' => array('a' => 1), 'rows' => array('textarea' => 1), 'rowspan' => array('td' => 1, 'th' => 1), 'rules' => array('table' => 1), 'scope' => array('td' => 1, 'th' => 1), 'scrolling' => array('iframe' => 1), 'selected' => array('option' => 1), 'shape' => array('area' => 1, 'a' => 1), 'size' => array('hr' => 1, 'font' => 1, 'input' => 1, 'select' => 1), 'span' => array('col' => 1, 'colgroup' => 1), 'src' => array('embed' => 1, 'script' => 1, 'input' => 1, 'iframe' => 1, 'img' => 1), 'standby' => array('object' => 1), 'start' => array('ol' => 1), 'summary' => array('table' => 1), 'tabindex' => array('a' => 1, 'area' => 1, 'button' => 1, 'input' => 1, 'object' => 1, 'select' => 1, 'textarea' => 1), 'target' => array('a' => 1, 'area' => 1, 'form' => 1), 'type' => array('a' => 1, 'embed' => 1, 'object' => 1, 'param' => 1, 'script' => 1, 'input' => 1, 'li' => 1, 'ol' => 1, 'ul' => 1, 'button' => 1), 'usemap' => array('img' => 1, 'input' => 1, 'object' => 1), 'valign' => array('col' => 1, 'colgroup' => 1, 'tbody' => 1, 'td' => 1, 'tfoot' => 1, 'th' => 1, 'thead' => 1, 'tr' => 1), 'value' => array('input' => 1, 'option' => 1, 'param' => 1, 'button' => 1, 'li' => 1), 'valuetype' => array('param' => 1), 'vspace' => array('applet' => 1, 'img' => 1, 'object' => 1), 'width' => array('embed' => 1, 'hr' => 1, 'iframe' => 1, 'img' => 1, 'object' => 1, 'table' => 1, 'td' => 1, 'th' => 1, 'applet' => 1, 'col' => 1, 'colgroup' => 1, 'pre' => 1), 'wmode' => array('embed' => 1), 'xml:space' => array('pre' => 1, 'script' => 1, 'style' => 1)); // Ele-specific
687696
static $aNE = array('allowfullscreen' => 1, 'checked' => 1, 'compact' => 1, 'declare' => 1, 'defer' => 1, 'disabled' => 1, 'ismap' => 1, 'multiple' => 1, 'nohref' => 1, 'noresize' => 1, 'noshade' => 1, 'nowrap' => 1, 'readonly' => 1, 'selected' => 1); // Empty
@@ -798,7 +807,7 @@ function hl_tag($t) {
798807
}
799808
}
800809
}
801-
if (isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($v, $rl[$k])) === 0) {
810+
if (isset($rl[$k]) && is_array($rl[$k]) && ($v = hl_attrval($k, $v, $rl[$k])) === 0) {
802811
continue;
803812
}
804813
$a[$k] = str_replace('"', '&quot;', $v);
@@ -946,17 +955,16 @@ function hl_tag2(&$e, &$a, $t = 1) {
946955
static $fs = array('0' => 'xx-small', '1' => 'xx-small', '2' => 'small', '3' => 'medium', '4' => 'large', '5' => 'x-large', '6' => 'xx-large', '7' => '300%', '-1' => 'smaller', '-2' => '60%', '+1' => 'larger', '+2' => '150%', '+3' => '200%', '+4' => '300%');
947956
if ($e == 'font') {
948957
$a2 = '';
949-
if (preg_match('`face\s*=\s*(\'|")([^=]+?)\\1`i', $a, $m) or preg_match('`face\s*=(\s*)(\S+)`i', $a, $m)) {
950-
$a2 .= ' font-family: '.str_replace('"', '\'', trim($m[2])).';';
951-
}
952-
if (preg_match('`color\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m)) {
953-
$a2 .= ' color: '.str_replace('"', '\'', trim($m[2])).';';
958+
while (preg_match('`(^|\s)(color|size)\s*=\s*(\'|")?(.+?)(\\3|\s|$)`i', $a, $m)) {
959+
$a = str_replace($m[0], ' ', $a);
960+
$a2 .= strtolower($m[2]) == 'color' ? (' color: '.str_replace('"', '\'', trim($m[4])).';') : (isset($fs[($m = trim($m[4]))]) ? ($a2 .= ' font-size: '.str_replace('"', '\'', $fs[$m]).';') : '');
954961
}
955-
if (preg_match('`size\s*=\s*(\'|")?(.+?)(\\1|\s|$)`i', $a, $m) && isset($fs[($m = trim($m[2]))])) {
956-
$a2 .= ' font-size: '.str_replace('"', '\'', $fs[$m]).';';
962+
while (preg_match('`(^|\s)face\s*=\s*(\'|")?([^=]+?)\\2`i', $a, $m) or preg_match('`(^|\s)face\s*=(\s*)(\S+)`i', $a, $m)) {
963+
$a = str_replace($m[0], ' ', $a);
964+
$a2 .= ' font-family: '.str_replace('"', '\'', trim($m[3])).';';
957965
}
958966
$e = 'span';
959-
return ltrim($a2);
967+
return ltrim(str_replace('<', '', $a2));
960968
}
961969
if ($t == 2) {
962970
$e = 0;
@@ -1043,7 +1051,7 @@ function hl_tidy($t, $w, $p) {
10431051

10441052
function hl_version() {
10451053
// rel
1046-
return '1.1.20';
1054+
return '1.1.22';
10471055
// eof
10481056
}
10491057

src/htmLawed/htmLawedTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
htmLawedTest.php, 28 May 2013
5-
htmLawed 1.1.20, 9 June 2015
5+
htmLawed 1.1.22, 5 March 2016
66
Copyright Santosh Patnaik
77
Dual licensed with LGPL 3 and GPL 2+
88
A PHP Labware internal utility - http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed
@@ -136,8 +136,7 @@ function hexdump($d) {
136136
<head>
137137
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
138138
<meta name="description" content="htmLawed <?php echo hl_version(); ?> test page"/>
139-
<style type="text/css"><!--
140-
/*--><![CDATA[/*><!--*/
139+
<style type="text/css"><!-- /*--><![CDATA[/*><!--*/
141140
a, a.resizer {
142141
text-decoration: none;
143142
}
@@ -290,7 +289,9 @@ function hexdump($d) {
290289
<![CDATA[//><!--
291290
window.name = 'hlmain';
292291
function hl(i) {
293-
<?php if(!$_hilite){echo 'return;'; }?>
292+
<?php if (!$_hilite) {
293+
echo 'return;';
294+
}?>
294295
var e = document.getElementById(i);
295296
if (!e) {
296297
return;
@@ -1106,7 +1107,6 @@ function diffLaunch() {
11061107
<div id="inputF" style="display: block;">
11071108

11081109
<input type="hidden" name="token" id="token" value="<?php echo $token; ?>"/>
1109-
11101110
<div><textarea id="text" class="textarea" name="text" rows="5" cols="100"
11111111
style="width: 100%;"><?php echo htmlspecialchars($_POST['text']); ?></textarea></div>
11121112
<input type="submit" id="submitF" name="submitF" value="Process" style="float:left;"

0 commit comments

Comments
 (0)