diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml deleted file mode 100644 index 2cdfa1d..0000000 --- a/.github/workflows/coding-standards.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: "CS" - -on: - pull_request: - push: - branches: - - master - -jobs: - coding-standards: - name: "CS Fixer" - runs-on: "ubuntu-20.04" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "7.4" - tools: cs2pr, pecl, composer:v2 - extensions: tidy - ini-values: "date.timezone=Europe/Paris" - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v2" - with: - composer-options: "--optimize-autoloader --prefer-dist" - - - name: "RUN PHP CS Fixer" - run: "php vendor/bin/php-cs-fixer fix --verbose --dry-run --format=checkstyle | cs2pr" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 34a927e..eb45dd9 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -9,7 +9,7 @@ on: jobs: phpunit: name: "PHP ${{ matrix.php }}" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-latest" strategy: fail-fast: false @@ -20,10 +20,13 @@ jobs: - "7.4" - "8.0" - "8.1" + - "8.2" + - "8.3" + - "8.4" steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v7" - name: "Install PHP" uses: "shivammathur/setup-php@v2" @@ -35,7 +38,7 @@ jobs: ini-values: "date.timezone=Europe/Paris" - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v4" with: composer-options: "--optimize-autoloader --prefer-dist" diff --git a/htmLawed.php b/htmLawed.php index bedad6e..be61bf3 100755 --- a/htmLawed.php +++ b/htmLawed.php @@ -1,1165 +1,1600 @@ + * @copyright (c) 2007-, Santosh Patnaik + * @dependency None + * @license LGPL 3 and GPL 2+ dual license + * @link https://bioinformatics.org/phplabware/internal_utilities/htmLawed + * @package htmLawed + * @php >=4.4 + * @time 2023-08-04 + * @version 1.2.15 */ -function htmLawed($t, $C = 1, $S = []) +/* + * Main function. + * Calls all other functions (alphabetically ordered further below). + * + * @param string $t HTM. + * @param mixed $C $config configuration option. + * @param mixed $S $spec specification option. + * @return string Filtered/sanitized $t. + */ +function htmLawed($t, $C=1, $S=array()) { - $C = is_array($C) ? $C : []; - if (!empty($C['valid_xhtml'])) { - $C['elements'] = empty($C['elements']) ? '*-acronym-big-center-dir-font-isindex-s-strike-tt' : $C['elements']; - $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 2; - $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 2; - } - // config eles - $e = ['a' => 1, 'abbr' => 1, 'acronym' => 1, 'address' => 1, 'applet' => 1, 'area' => 1, 'article' => 1, 'aside' => 1, 'audio' => 1, 'b' => 1, 'bdi' => 1, 'bdo' => 1, 'big' => 1, 'blockquote' => 1, 'br' => 1, 'button' => 1, 'canvas' => 1, 'caption' => 1, 'center' => 1, 'cite' => 1, 'code' => 1, 'col' => 1, 'colgroup' => 1, 'command' => 1, 'data' => 1, 'datalist' => 1, 'dd' => 1, 'del' => 1, 'details' => 1, 'dialog' => 1, 'dfn' => 1, 'dir' => 1, 'div' => 1, 'dl' => 1, 'dt' => 1, 'em' => 1, 'embed' => 1, 'fieldset' => 1, 'figcaption' => 1, 'figure' => 1, 'font' => 1, 'footer' => 1, 'form' => 1, 'h1' => 1, 'h2' => 1, 'h3' => 1, 'h4' => 1, 'h5' => 1, 'h6' => 1, 'header' => 1, 'hgroup' => 1, 'hr' => 1, 'i' => 1, 'iframe' => 1, 'img' => 1, 'input' => 1, 'ins' => 1, 'isindex' => 1, 'kbd' => 1, 'keygen' => 1, 'label' => 1, 'legend' => 1, 'li' => 1, 'link' => 1, 'main' => 1, 'map' => 1, 'mark' => 1, 'menu' => 1, 'meta' => 1, 'meter' => 1, 'nav' => 1, 'noscript' => 1, 'object' => 1, 'ol' => 1, 'optgroup' => 1, 'option' => 1, 'output' => 1, 'p' => 1, 'param' => 1, 'picture' => 1, 'pre' => 1, 'progress' => 1, 'q' => 1, 'rb' => 1, 'rbc' => 1, 'rp' => 1, 'rt' => 1, 'rtc' => 1, 'ruby' => 1, 's' => 1, 'samp' => 1, 'script' => 1, 'section' => 1, 'select' => 1, 'slot' => 1, 'small' => 1, 'source' => 1, 'span' => 1, 'strike' => 1, 'strong' => 1, 'style' => 1, 'sub' => 1, 'summary' => 1, 'sup' => 1, 'table' => 1, 'tbody' => 1, 'td' => 1, 'template' => 1, 'textarea' => 1, 'tfoot' => 1, 'th' => 1, 'thead' => 1, 'time' => 1, 'tr' => 1, 'track' => 1, 'tt' => 1, 'u' => 1, 'ul' => 1, 'var' => 1, 'video' => 1, 'wbr' => 1]; // 122 incl. deprecated & some Ruby + // Standard elements including deprecated. - if (!empty($C['safe'])) { - unset($e['applet'], $e['audio'], $e['canvas'], $e['dialog'], $e['embed'], $e['iframe'], $e['object'], $e['script'], $e['video']); - } - $x = !empty($C['elements']) ? str_replace(["\n", "\r", "\t", ' '], '', strtolower($C['elements'])) : '*'; - if ('-*' === $x) { - $e = []; - } elseif (false === strpos($x, '*')) { - $e = array_flip(explode(',', $x)); - } else { - if (isset($x[1])) { - if (strpos($x, '(')) { - $x = preg_replace_callback('`\([^()]+\)`', function ($m) {return str_replace(['(', ')', '-'], ['', '', 'A'], $m[0]); }, $x); - } + $eleAr = array('a'=>1, 'abbr'=>1, 'acronym'=>1, 'address'=>1, 'applet'=>1, 'area'=>1, 'article'=>1, 'aside'=>1, 'audio'=>1, 'b'=>1, 'bdi'=>1, 'bdo'=>1, 'big'=>1, 'blockquote'=>1, 'br'=>1, 'button'=>1, 'canvas'=>1, 'caption'=>1, 'center'=>1, 'cite'=>1, 'code'=>1, 'col'=>1, 'colgroup'=>1, 'command'=>1, 'data'=>1, 'datalist'=>1, 'dd'=>1, 'del'=>1, 'details'=>1, 'dialog'=>1, 'dfn'=>1, 'dir'=>1, 'div'=>1, 'dl'=>1, 'dt'=>1, 'em'=>1, 'embed'=>1, 'fieldset'=>1, 'figcaption'=>1, 'figure'=>1, 'font'=>1, 'footer'=>1, 'form'=>1, 'h1'=>1, 'h2'=>1, 'h3'=>1, 'h4'=>1, 'h5'=>1, 'h6'=>1, 'header'=>1, 'hgroup'=>1, 'hr'=>1, 'i'=>1, 'iframe'=>1, 'img'=>1, 'input'=>1, 'ins'=>1, 'isindex'=>1, 'kbd'=>1, 'keygen'=>1, 'label'=>1, 'legend'=>1, 'li'=>1, 'link'=>1, 'main'=>1, 'map'=>1, 'mark'=>1, 'menu'=>1, 'meta'=>1, 'meter'=>1, 'nav'=>1, 'noscript'=>1, 'object'=>1, 'ol'=>1, 'optgroup'=>1, 'option'=>1, 'output'=>1, 'p'=>1, 'param'=>1, 'picture'=>1, 'pre'=>1, 'progress'=>1, 'q'=>1, 'rb'=>1, 'rbc'=>1, 'rp'=>1, 'rt'=>1, 'rtc'=>1, 'ruby'=>1, 's'=>1, 'samp'=>1, 'script'=>1, 'section'=>1, 'select'=>1, 'slot'=>1, 'small'=>1, 'source'=>1, 'span'=>1, 'strike'=>1, 'strong'=>1, 'style'=>1, 'sub'=>1, 'summary'=>1, 'sup'=>1, 'table'=>1, 'tbody'=>1, 'td'=>1, 'template'=>1, 'textarea'=>1, 'tfoot'=>1, 'th'=>1, 'thead'=>1, 'time'=>1, 'tr'=>1, 'track'=>1, 'tt'=>1, 'u'=>1, 'ul'=>1, 'var'=>1, 'video'=>1, 'wbr'=>1); - preg_match_all('`(?:^|-|\+)[^\-+]+?(?=-|\+|$)`', $x, $m, \PREG_SET_ORDER); - for ($i = count($m); --$i >= 0;) { - $m[$i] = $m[$i][0]; - } - foreach ($m as $v) { - $v = str_replace('A', '-', $v); - if ('+' === $v[0]) { - $e[substr($v, 1)] = 1; - } elseif ('-' === $v[0]) { - if (strpos($v, '-', 1)) { - $e[$v] = 1; - } elseif (isset($e[($v = substr($v, 1))]) && !in_array('+' . $v, $m, true)) { - unset($e[$v]); - } - } - } - } - } - $C['elements'] = &$e; - // config attrs - $x = !empty($C['deny_attribute']) ? strtolower(preg_replace('"\s+-"', '/', trim($C['deny_attribute']))) : ''; - $x = array_flip((isset($x[0]) && '*' === $x[0]) ? explode('/', $x) : explode(',', $x . (!empty($C['safe']) ? ',on*' : ''))); - $C['deny_attribute'] = $x; - // config URLs - $x = (isset($C['schemes'][2]) && strpos($C['schemes'], ':')) ? strtolower($C['schemes']) : 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, tel, telnet' . (empty($C['safe']) ? ', app, javascript; *: data, javascript, ' : '; *:') . 'file, http, https'; - $C['schemes'] = []; - foreach (explode(';', trim(str_replace([' ', "\t", "\r", "\n"], '', $x), ';')) as $v) { - $x = $x2 = null; - list($x, $x2) = explode(':', $v, 2); - if ($x2) { - $C['schemes'][$x] = array_flip(explode(',', $x2)); - } - } - if (!isset($C['schemes']['*'])) { - $C['schemes']['*'] = ['file' => 1, 'http' => 1, 'https' => 1]; - if (empty($C['safe'])) { - $C['schemes']['*'] += ['data' => 1, 'javascript' => 1]; - } - } - if (!empty($C['safe']) && empty($C['schemes']['style'])) { - $C['schemes']['style'] = ['!' => 1]; - } - $C['abs_url'] = isset($C['abs_url']) ? $C['abs_url'] : 0; - if (!isset($C['base_url']) || !preg_match('`^[a-zA-Z\d.+\-]+://[^/]+/(.+?/)?$`', $C['base_url'])) { - $C['base_url'] = $C['abs_url'] = 0; - } - // config rest - $C['and_mark'] = empty($C['and_mark']) ? 0 : 1; - $C['anti_link_spam'] = (isset($C['anti_link_spam']) && is_array($C['anti_link_spam']) && 2 === count($C['anti_link_spam']) && (empty($C['anti_link_spam'][0]) || hl_regex($C['anti_link_spam'][0])) && (empty($C['anti_link_spam'][1]) || hl_regex($C['anti_link_spam'][1]))) ? $C['anti_link_spam'] : 0; - $C['anti_mail_spam'] = isset($C['anti_mail_spam']) ? $C['anti_mail_spam'] : 0; - $C['any_custom_element'] = (!isset($C['any_custom_element']) || !empty($C['any_custom_element'])) ? 1 : 0; - $C['balance'] = isset($C['balance']) ? (bool) $C['balance'] : 1; - $C['cdata'] = isset($C['cdata']) ? $C['cdata'] : (empty($C['safe']) ? 3 : 0); - $C['clean_ms_char'] = empty($C['clean_ms_char']) ? 0 : $C['clean_ms_char']; - $C['comment'] = isset($C['comment']) ? $C['comment'] : (empty($C['safe']) ? 3 : 0); - $C['css_expression'] = empty($C['css_expression']) ? 0 : 1; - $C['direct_list_nest'] = empty($C['direct_list_nest']) ? 0 : 1; - $C['hexdec_entity'] = isset($C['hexdec_entity']) ? $C['hexdec_entity'] : 1; - $C['hook'] = (!empty($C['hook']) && function_exists($C['hook'])) ? $C['hook'] : 0; - $C['hook_tag'] = (!empty($C['hook_tag']) && function_exists($C['hook_tag'])) ? $C['hook_tag'] : 0; - $C['keep_bad'] = isset($C['keep_bad']) ? $C['keep_bad'] : 6; - $C['lc_std_val'] = isset($C['lc_std_val']) ? (bool) $C['lc_std_val'] : 1; - $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 1; - $C['named_entity'] = isset($C['named_entity']) ? (bool) $C['named_entity'] : 1; - $C['no_deprecated_attr'] = isset($C['no_deprecated_attr']) ? $C['no_deprecated_attr'] : 1; - $C['parent'] = isset($C['parent'][0]) ? strtolower($C['parent']) : 'body'; - $C['show_setting'] = !empty($C['show_setting']) ? $C['show_setting'] : 0; - $C['style_pass'] = empty($C['style_pass']) ? 0 : 1; - $C['tidy'] = empty($C['tidy']) ? 0 : $C['tidy']; - $C['unique_ids'] = isset($C['unique_ids']) && (!preg_match('`\W`', $C['unique_ids'])) ? $C['unique_ids'] : 1; - $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 0; - - if (isset($GLOBALS['C'])) { - $reC = $GLOBALS['C']; - } - $GLOBALS['C'] = $C; - $S = is_array($S) ? $S : hl_spec($S); - if (isset($GLOBALS['S'])) { - $reS = $GLOBALS['S']; - } - $GLOBALS['S'] = $S; + // Set $C array ($config), using default parameters as needed. - $t = preg_replace('`[\x00-\x08\x0b-\x0c\x0e-\x1f]`', '', $t); - if ($C['clean_ms_char']) { - $x = ["\x7f" => '', "\x80" => '€', "\x81" => '', "\x83" => 'ƒ', "\x85" => '…', "\x86" => '†', "\x87" => '‡', "\x88" => 'ˆ', "\x89" => '‰', "\x8a" => 'Š', "\x8b" => '‹', "\x8c" => 'Œ', "\x8d" => '', "\x8e" => 'Ž', "\x8f" => '', "\x90" => '', "\x95" => '•', "\x96" => '–', "\x97" => '—', "\x98" => '˜', "\x99" => '™', "\x9a" => 'š', "\x9b" => '›', "\x9c" => 'œ', "\x9d" => '', "\x9e" => 'ž', "\x9f" => 'Ÿ']; - $x = $x + (1 === $C['clean_ms_char'] ? ["\x82" => '‚', "\x84" => '„', "\x91" => '‘', "\x92" => '’', "\x93" => '“', "\x94" => '”'] : ["\x82" => '\'', "\x84" => '"', "\x91" => '\'', "\x92" => '\'', "\x93" => '"', "\x94" => '"']); - $t = strtr($t, $x); - } - if ($C['cdata'] || $C['comment']) { - $t = preg_replace_callback('``sm', 'hl_cmtcd', $t); - } - $t = preg_replace_callback('`&([a-zA-Z][a-zA-Z0-9]{1,30}|#(?:[0-9]{1,8}|[Xx][0-9A-Fa-f]{1,7}));`', 'hl_ent', str_replace('&', '&', $t)); - if ($C['unique_ids'] && !isset($GLOBALS['hl_Ids'])) { - $GLOBALS['hl_Ids'] = []; - } - if ($C['hook']) { - $t = $C['hook']($t, $C, $S); - } - if ($C['show_setting'] && preg_match('`^[a-z][a-z0-9_]*$`i', $C['show_setting'])) { - $GLOBALS[$C['show_setting']] = ['config' => $C, 'spec' => $S, 'time' => microtime()]; - } - // main - $t = preg_replace_callback('`<(?:(?:\s|$)|(?:[^>]*(?:>|$)))|>`m', 'hl_tag', $t); - $t = $C['balance'] ? hl_bal($t, $C['keep_bad'], $C['parent']) : $t; - $t = (($C['cdata'] || $C['comment']) && false !== strpos($t, "\x01")) ? str_replace(["\x01", "\x02", "\x03", "\x04", "\x05"], ['', '', '&', '<', '>'], $t) : $t; - $t = $C['tidy'] ? hl_tidy($t, $C['tidy'], $C['parent']) : $t; - unset($C, $e); - if (isset($reC)) { - $GLOBALS['C'] = $reC; - } - if (isset($reS)) { - $GLOBALS['S'] = $reS; - } + $C = is_array($C) ? $C : array(); + if (!empty($C['valid_xhtml'])) { + $C['elements'] = empty($C['elements']) ? '*-acronym-big-center-dir-font-isindex-s-strike-tt' : $C['elements']; + $C['make_tag_strict'] = isset($C['make_tag_strict']) ? $C['make_tag_strict'] : 2; + $C['xml:lang'] = isset($C['xml:lang']) ? $C['xml:lang'] : 2; + } - return $t; -} + // -- Configure for elements. -function hl_attrval($a, $t, $p) -{ - // check attr val against $S - static $ma = ['accesskey', 'class', 'itemtype', 'rel']; - $s = in_array($a, $ma, true) ? ' ' : ('srcset' === $a ? ',' : ''); - $r = []; - $t = !empty($s) ? explode($s, $t) : [$t]; - foreach ($t as $tk => $tv) { - $o = 1; - $tv = trim($tv); - $l = strlen($tv); - foreach ($p as $k => $v) { - if (!$l) { - continue; - } - switch ($k) { - case 'maxlen': - if ($l > $v) { - $o = 0; - } - break; - case 'minlen': - if ($l < $v) { - $o = 0; - } - break; - case 'maxval': - if ((float) ($tv) > $v) { - $o = 0; - } - break; - case 'minval': - if ((float) ($tv) < $v) { - $o = 0; - } - break; - case 'match': - if (!preg_match($v, $tv)) { - $o = 0; - } - break; - case 'nomatch': - if (preg_match($v, $tv)) { - $o = 0; - } - break; - case 'oneof': - $m = 0; - foreach (explode('|', $v) as $n) { - if ($tv === $n) { - $m = 1; - break; - } - } - $o = $m; - break; - case 'noneof': - $m = 1; - foreach (explode('|', $v) as $n) { - if ($tv === $n) { - $m = 0; - break; - } - } - $o = $m; - break; - default: - break; - } - if (!$o) { - break; - } - } - if ($o) { - $r[] = $tv; + if (!empty($C['safe'])) { + unset($eleAr['applet'], $eleAr['audio'], $eleAr['canvas'], $eleAr['dialog'], $eleAr['embed'], $eleAr['iframe'], $eleAr['object'], $eleAr['script'], $eleAr['video']); + } + $x = !empty($C['elements']) ? str_replace(array("\n", "\r", "\t", ' '), '', strtolower($C['elements'])) : '*'; + if ($x == '-*') { + $eleAr = array(); + } elseif (strpos($x, '*') === false) { + $eleAr = array_flip(explode(',', $x)); + } else { + if (isset($x[1])) { + if (strpos($x, '(')) { // Temporarily replace hyphen of custom element, minus being special character + $x = + preg_replace_callback( + '`\([^()]+\)`', + function ($m) { + return str_replace(array('(', ')', '-'), array('', '', 'A'), $m[0]); + }, + $x); + } + preg_match_all('`(?:^|-|\+)[^\-+]+?(?=-|\+|$)`', $x, $m, PREG_SET_ORDER); + for ($i=count($m); --$i>=0;) { + $m[$i] = $m[$i][0]; + } + foreach ($m as $v) { + $v = str_replace('A', '-', $v); + if ($v[0] == '+') { + $eleAr[substr($v, 1)] = 1; + } elseif ($v[0] == '-') { + if (strpos($v, '-', 1)) { + $eleAr[$v] = 1; + } elseif (isset($eleAr[($v = substr($v, 1))]) && !in_array('+'. $v, $m)) { + unset($eleAr[$v]); + } } + } } - if (',' === $s) { - $s = ', '; - } - $r = implode($s, $r); + } + $C['elements'] =& $eleAr; - return isset($r[0]) ? $r : (isset($p['default']) ? $p['default'] : 0); -} + // -- Configure for attributes. -function hl_bal($t, $do = 1, $in = 'div') -{ - // balance tags - // by content - $cB = ['blockquote' => 1, 'form' => 1, 'map' => 1, 'noscript' => 1]; // Block - $cE = ['area' => 1, 'br' => 1, 'col' => 1, 'command' => 1, 'embed' => 1, 'hr' => 1, 'img' => 1, 'input' => 1, 'isindex' => 1, 'keygen' => 1, 'link' => 1, 'meta' => 1, 'param' => 1, 'source' => 1, 'track' => 1, 'wbr' => 1]; // Empty - $cF = ['a' => 1, 'article' => 1, 'aside' => 1, 'audio' => 1, 'button' => 1, 'canvas' => 1, 'del' => 1, 'details' => 1, 'dialog' => 1, 'div' => 1, 'dd' => 1, 'fieldset' => 1, 'figure' => 1, 'footer' => 1, 'header' => 1, 'iframe' => 1, 'ins' => 1, 'li' => 1, 'main' => 1, 'menu' => 1, 'nav' => 1, 'noscript' => 1, 'object' => 1, 'section' => 1, 'slot' => 1, 'style' => 1, 'td' => 1, 'template' => 1, 'th' => 1, 'video' => 1]; // Flow; later context-wise dynamic move of ins & del to $cI - $cI = ['abbr' => 1, 'acronym' => 1, 'address' => 1, 'b' => 1, 'bdi' => 1, 'bdo' => 1, 'big' => 1, 'caption' => 1, 'cite' => 1, 'code' => 1, 'data' => 1, 'datalist' => 1, 'dfn' => 1, 'dt' => 1, 'em' => 1, 'figcaption' => 1, 'font' => 1, 'h1' => 1, 'h2' => 1, 'h3' => 1, 'h4' => 1, 'h5' => 1, 'h6' => 1, 'hgroup' => 1, 'i' => 1, 'kbd' => 1, 'label' => 1, 'legend' => 1, 'mark' => 1, 'meter' => 1, 'output' => 1, 'p' => 1, 'picture' => 1, 'pre' => 1, 'progress' => 1, 'q' => 1, 'rb' => 1, 'rt' => 1, 's' => 1, 'samp' => 1, 'small' => 1, 'span' => 1, 'strike' => 1, 'strong' => 1, 'sub' => 1, 'summary' => 1, 'sup' => 1, 'time' => 1, 'tt' => 1, 'u' => 1, 'var' => 1]; // Inline - $cN = ['a' => ['a' => 1, 'address' => 1, 'button' => 1, 'details' => 1, 'embed' => 1, 'keygen' => 1, 'label' => 1, 'select' => 1, 'textarea' => 1], 'address' => ['address' => 1, 'article' => 1, 'aside' => 1, 'header' => 1, 'keygen' => 1, 'footer' => 1, 'nav' => 1, 'section' => 1], 'button' => ['a' => 1, 'address' => 1, 'button' => 1, 'details' => 1, 'embed' => 1, 'fieldset' => 1, 'form' => 1, 'iframe' => 1, 'input' => 1, 'keygen' => 1, 'label' => 1, 'select' => 1, 'textarea' => 1], 'fieldset' => ['fieldset' => 1], 'footer' => ['header' => 1, 'footer' => 1], 'form' => ['form' => 1], 'header' => ['header' => 1, 'footer' => 1], 'label' => ['label' => 1], 'main' => ['main' => 1], 'meter' => ['meter' => 1], 'noscript' => ['script' => 1], 'pre' => ['big' => 1, 'font' => 1, 'img' => 1, 'object' => 1, 'script' => 1, 'small' => 1, 'sub' => 1, 'sup' => 1], 'progress' => ['progress' => 1], 'rb' => ['ruby' => 1], 'rt' => ['ruby' => 1], 'time' => ['time' => 1]]; // Illegal - $cN2 = array_keys($cN); - $cS = ['colgroup' => ['col' => 1], 'datalist' => ['option' => 1], 'dir' => ['li' => 1], 'dl' => ['dd' => 1, 'dt' => 1], 'hgroup' => ['h1' => 1, 'h2' => 1, 'h3' => 1, 'h4' => 1, 'h5' => 1, 'h6' => 1], 'menu' => ['li' => 1], 'ol' => ['li' => 1], 'optgroup' => ['option' => 1], 'option' => ['#pcdata' => 1], 'rbc' => ['rb' => 1], 'rp' => ['#pcdata' => 1], 'rtc' => ['rt' => 1], 'ruby' => ['rb' => 1, 'rbc' => 1, 'rp' => 1, 'rt' => 1, 'rtc' => 1, '#pcdata' => 1], 'select' => ['optgroup' => 1, 'option' => 1], 'script' => ['#pcdata' => 1], 'table' => ['caption' => 1, 'col' => 1, 'colgroup' => 1, 'tfoot' => 1, 'tbody' => 1, 'tr' => 1, 'thead' => 1], 'tbody' => ['tr' => 1], 'tfoot' => ['tr' => 1], 'textarea' => ['#pcdata' => 1], 'thead' => ['tr' => 1], 'tr' => ['td' => 1, 'th' => 1], 'ul' => ['li' => 1]]; // Specific - immediate parent-child - if ($GLOBALS['C']['direct_list_nest']) { - $cS['ol'] = $cS['ul'] = $cS['menu'] += ['menu' => 1, 'ol' => 1, 'ul' => 1]; - } - $cO = ['address' => ['p' => 1], 'applet' => ['param' => 1], 'audio' => ['source' => 1, 'track' => 1], 'blockquote' => ['script' => 1], 'details' => ['summary' => 1], 'fieldset' => ['legend' => 1, '#pcdata' => 1], 'figure' => ['figcaption' => 1], 'form' => ['script' => 1], 'map' => ['area' => 1], 'object' => ['param' => 1, 'embed' => 1], 'video' => ['source' => 1, 'track' => 1]]; // Other - $cT = ['colgroup' => 1, 'dd' => 1, 'dt' => 1, 'li' => 1, 'option' => 1, 'p' => 1, 'td' => 1, 'tfoot' => 1, 'th' => 1, 'thead' => 1, 'tr' => 1]; // Omitable closing - // block/inline type; a/ins/del both type; #pcdata: text - $eB = ['a' => 1, 'address' => 1, 'article' => 1, 'aside' => 1, 'blockquote' => 1, 'center' => 1, 'del' => 1, 'details' => 1, 'dialog' => 1, 'dir' => 1, 'dl' => 1, 'div' => 1, 'fieldset' => 1, 'figure' => 1, 'footer' => 1, 'form' => 1, 'ins' => 1, 'h1' => 1, 'h2' => 1, 'h3' => 1, 'h4' => 1, 'h5' => 1, 'h6' => 1, 'header' => 1, 'hr' => 1, 'isindex' => 1, 'main' => 1, 'menu' => 1, 'nav' => 1, 'noscript' => 1, 'ol' => 1, 'p' => 1, 'pre' => 1, 'section' => 1, 'slot' => 1, 'style' => 1, 'table' => 1, 'template' => 1, 'ul' => 1]; - $eI = ['#pcdata' => 1, 'a' => 1, 'abbr' => 1, 'acronym' => 1, 'applet' => 1, 'audio' => 1, 'b' => 1, 'bdi' => 1, 'bdo' => 1, 'big' => 1, 'br' => 1, 'button' => 1, 'canvas' => 1, 'cite' => 1, 'code' => 1, 'command' => 1, 'data' => 1, 'datalist' => 1, 'del' => 1, 'dfn' => 1, 'em' => 1, 'embed' => 1, 'figcaption' => 1, 'font' => 1, 'i' => 1, 'iframe' => 1, 'img' => 1, 'input' => 1, 'ins' => 1, 'kbd' => 1, 'label' => 1, 'link' => 1, 'map' => 1, 'mark' => 1, 'meta' => 1, 'meter' => 1, 'object' => 1, 'output' => 1, 'picture' => 1, 'progress' => 1, 'q' => 1, 'ruby' => 1, 's' => 1, 'samp' => 1, 'select' => 1, 'script' => 1, 'small' => 1, 'span' => 1, 'strike' => 1, 'strong' => 1, 'sub' => 1, 'summary' => 1, 'sup' => 1, 'textarea' => 1, 'time' => 1, 'tt' => 1, 'u' => 1, 'var' => 1, 'video' => 1, 'wbr' => 1]; - $eN = ['a' => 1, 'address' => 1, 'article' => 1, 'aside' => 1, 'big' => 1, 'button' => 1, 'details' => 1, 'embed' => 1, 'fieldset' => 1, 'font' => 1, 'footer' => 1, 'form' => 1, 'header' => 1, 'iframe' => 1, 'img' => 1, 'input' => 1, 'keygen' => 1, 'label' => 1, 'meter' => 1, 'nav' => 1, 'object' => 1, 'progress' => 1, 'ruby' => 1, 'script' => 1, 'select' => 1, 'small' => 1, 'sub' => 1, 'sup' => 1, 'textarea' => 1, 'time' => 1]; // Exclude from specific ele; $cN values - $eO = ['area' => 1, 'caption' => 1, 'col' => 1, 'colgroup' => 1, 'command' => 1, 'dd' => 1, 'dt' => 1, 'hgroup' => 1, 'keygen' => 1, 'legend' => 1, 'li' => 1, 'optgroup' => 1, 'option' => 1, 'param' => 1, 'rb' => 1, 'rbc' => 1, 'rp' => 1, 'rt' => 1, 'rtc' => 1, 'script' => 1, 'source' => 1, 'tbody' => 1, 'td' => 1, 'tfoot' => 1, 'thead' => 1, 'th' => 1, 'tr' => 1, 'track' => 1]; // Missing in $eB & $eI - $eF = $eB + $eI; - - // $in sets allowed child - $in = ((isset($eF[$in]) && '#pcdata' !== $in) || isset($eO[$in])) ? $in : 'div'; - if (isset($cE[$in])) { - return !$do ? '' : str_replace(['<', '>'], ['<', '>'], $t); - } - if (isset($cS[$in])) { - $inOk = $cS[$in]; - } elseif (isset($cI[$in])) { - $inOk = $eI; - $cI['del'] = 1; - $cI['ins'] = 1; - } elseif (isset($cF[$in])) { - $inOk = $eF; - unset($cI['del'], $cI['ins']); - } elseif (isset($cB[$in])) { - $inOk = $eB; - unset($cI['del'], $cI['ins']); - } - if (isset($cO[$in])) { - $inOk = $inOk + $cO[$in]; - } - if (isset($cN[$in])) { - $inOk = array_diff_assoc($inOk, $cN[$in]); - } - if (strpos($in, '-')) { - $inOk = ['*' => 1, '#pcdata' => 1]; - } // custom ele + $x = !empty($C['deny_attribute']) ? strtolower(preg_replace('"\s+-"', '/', trim($C['deny_attribute']))) : ''; + $x = str_replace(array(' ', "\t", "\r", "\n"), '', $x); + $x = + array_flip( + (isset($x[0]) && $x[0] == '*') + ? preg_replace( + '`^[^*]`', + '-'. '\\0', + explode( + '/', + (!empty($C['safe']) ? preg_replace('`/on[^/]+`', '', $x) : $x))) + : array_filter(explode(',', $x. (!empty($C['safe']) ? ',on*' : '')))); + $C['deny_attribute'] = $x; - $t = explode('<', $t); - $ok = $q = []; // $q seq list of open non-empty ele - ob_start(); + // -- Configure URL handling. - for ($i = -1, $ci = count($t); ++$i < $ci;) { - // allowed $ok in parent $p - if ($ql = count($q)) { - $p = array_pop($q); - $q[] = $p; - if (isset($cS[$p])) { - $ok = $cS[$p]; - } elseif (isset($cI[$p])) { - $ok = $eI; - $cI['del'] = 1; - $cI['ins'] = 1; - } elseif (isset($cF[$p])) { - $ok = $eF; - unset($cI['del'], $cI['ins']); - } elseif (isset($cB[$p])) { - $ok = $eB; - unset($cI['del'], $cI['ins']); - } - if (isset($cO[$p])) { - $ok = $ok + $cO[$p]; - } - if (isset($cN[$p])) { - $ok = array_diff_assoc($ok, $cN[$p]); - } - if (strpos($p, '-')) { - $ok = ['*' => 1, '#pcdata' => 1]; - } - } else { - $ok = $inOk; - unset($cI['del'], $cI['ins']); - } - // bad tags, & ele content - if (isset($e) && (1 === $do || (isset($ok['#pcdata']) && (3 === $do || 5 === $do)))) { - echo '<', $s, $e, $a, '>'; - } - if (isset($x[0])) { - if (strlen(trim($x)) && (($ql && isset($cB[$p])) || (isset($cB[$in]) && !$ql))) { - echo '
$spec = 'img=vFlag; input=rel'
@@ -612,7 +622,7 @@ a, abbr, acronym, address, applet, area, article, aside, audio, b, bdi, bdo, big, blockquote, br, button, canvas, caption, center, cite, code, col, colgroup, command, data, datalist, dd, del, details, dfn, dir, div, dl, dt, em, embed, fieldset, figcaption, figure, font, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, i, iframe, img, input, ins, isindex, kbd, keygen, label, legend, li, link, main, map, mark, menu, meta, meter, nav, noscript, object, ol, optgroup, option, output, p, param, pre, progress, q, rb, rbc, rp, rt, rtc, ruby, s, samp, script, section, select, small, source, span, strike, strong, style, sub, summary, sup, table, tbody, td, textarea, tfoot, th, thead, time, tr, track, tt, u, ul, var, video, wbr
+ a, abbr, acronym, address, applet, area, article, aside, audio, b, bdi, bdo, big, blockquote, br, button, canvas, caption, center, cite, code, col, colgroup, command, data, datalist, dd, del, details, dfn, dialog, dir, div, dl, dt, em, embed, fieldset, figcaption, figure, font, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, i, iframe, img, input, ins, isindex, kbd, keygen, label, legend, li, link, main, map, mark, menu, meta, meter, nav, noscript, object, ol, optgroup, option, output, p, param, picture, pre, progress, q, rb, rbc, rp, rt, rtc, ruby, s, samp, script, section, select, slot, small, source, span, strike, strong, style, sub, summary, sup, table, tbody, td, template, textarea, tfoot, th, thead, time, tr, track, tt, u, ul, var, video, wbr
<div style="text-align: center;">
The PHP <span style="text-decoration: line-through;">software</span> script used for this <span style="text-decoration: line-through;">web-page</span> web-page is <span style="font-weight: bold; font-family: arial; color: red; font-size: 200%;">htmLawedTest.php</span>, from <span style="color:green; text-decoration: underline;">PHP Labware</span>.
+ The PHP <span style="text-decoration: line-through;">software</span> script used for this <span style="text-decoration: line-through;">web-page</span> web-page is <span style="font-weight: bold; font-size: 200%; color: red; font-family: arial;">htmLawedTest.php</span>, from <u style="color:green">PHP Labware</u>.
</div>
@@ -1164,7 +1181,7 @@ 0-9 | . | _ | #xB7 | #xC0-#xD6 | #xD8-#xF6 | #xF8-#x37D | #x37F-#x1FFF | #x200C-#x200D | #x203F-#x2040 | #x2070-#x218F | #x2C00-#x2FEF | #x3001-#xD7FF | #xF900-#xFDCF | #xFDF0-#xFFFD | [#x10000-#xEFFFF]
+ aim, app, feed, file, ftp, gopher, http, https, javascript, irc, mailto, news, nntp, sftp, ssh, tel, telnet
+ aim, app, feed, file, ftp, gopher, http, https, javascript, irc, mailto, news, nntp, sftp, ssh, tel, telnet, ws, wss
action, cite, classid, codebase, data, itemtype, longdesc, model, pluginspage, pluginurl, src, srcset, style, usemap, and event attributes like onclick
+ action, archive, cite, classid, codebase, data, formaction, itemtype, longdesc, model, pluginspage, pluginurl, poster, src, srcset, style, usemap, and event attributes like onclick
deny_attribute - on*
elements - * -applet -audio -canvas -embed -iframe -object -script -video
+ elements - * -applet -audio -canvas -dialog -embed -iframe -object -script -video
schemes - href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, tel, telnet; style: !; *:file, http, https
+ schemes - href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, tel, telnet, ws, wss; style: !; *:file, http, https, ws, wss
$processed = htmLawed($text, array('safe'=>1, 'deny_attribute'=>'style'));
-htmLawed 1.2.4.2, 16 May 2019
+
+htmLawed 1.2.15
Copyright Santosh Patnaik
Dual licensed with LGPL 3 and GPL 2+
-A PHP Labware internal utility - http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed