• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xemlock / htmlpurifier-html5 / 13179873326

06 Feb 2025 01:28PM UTC coverage: 99.276% (-0.1%) from 99.406%
13179873326

push

github

web-flow
PHP 8.4 support (#84)

1 of 4 new or added lines in 1 file covered. (25.0%)

1508 of 1519 relevant lines covered (99.28%)

3883.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/library/HTMLPurifier/AttrDef/HTML5/Rel.php
1
<?php
2

3
/**
4
 * Shared validation logic for 'rel' attribute on <a>, <area>, <form> and <link> elements,
5
 * as defined by the HTML5 spec and the MicroFormats link type extensions tables.
6
 *
7
 * @see https://html.spec.whatwg.org/multipage/links.html#linkTypes
8
 */
9
abstract class HTMLPurifier_AttrDef_HTML5_Rel extends HTMLPurifier_AttrDef
10
{
11
    /**
12
     * Lookup table for valid rel values.
13
     * Stored as a static variable to minimize serialization footprint.
14
     * @var array
15
     */
16
    protected static $values = array();
17

18
    /**
19
     * Lazy loaded lookup for allowed rel values, based on provided config.
20
     * @var array
21
     */
22
    protected $allowed;
23

24
    /**
25
     * @param string $string
26
     * @param HTMLPurifier_Config $config
27
     * @param HTMLPurifier_Context $context
28
     * @return bool|string
29
     */
30
    public function validate($string, $config, $context)
31
    {
32
        if ($this->allowed === null) {
228✔
33
            $allowedRel = (array) $config->get('Attr.AllowedRel');
228✔
34
            if (empty($allowedRel)) {
228✔
35
                $allowed = array();
24✔
36
            } else {
4✔
37
                $allowed = array_intersect_key($allowedRel, static::$values);
204✔
38
            }
39
            $this->allowed = $allowed;
228✔
40
        }
38✔
41

42
        $string = $this->parseCDATA($string);
228✔
43
        $parts = explode(' ', $string);
228✔
44

45
        $result = array();
228✔
46
        foreach ($parts as $part) {
228✔
47
            // Link type keywords are always ASCII case-insensitive, and must be compared as such.
48
            // https://html.spec.whatwg.org/multipage/links.html#linkTypes
49
            $part = strtolower(trim($part));
228✔
50
            if (!isset($this->allowed[$part])) {
228✔
51
                continue;
84✔
52
            }
53
            $result[$part] = true;
204✔
54
        }
38✔
55

56
        if (empty($result)) {
228✔
57
            return false;
60✔
58
        }
59

60
        return implode(' ', array_keys($result));
204✔
61
    }
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc