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

xemlock / htmlpurifier-html5 / 13168072550

05 Feb 2025 10:52PM UTC coverage: 99.406%. Remained the same
13168072550

push

github

xemlock
Adjust tests for HTMLPurifier 4.18.0

Support for conditional comments was removed in HTMLPurifier 4.18.0,
see: https://github.com/ezyang/htmlpurifier/commit/4828fdf.

1507 of 1516 relevant lines covered (99.41%)

3215.37 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) {
190✔
33
            $allowedRel = (array) $config->get('Attr.AllowedRel');
190✔
34
            if (empty($allowedRel)) {
190✔
35
                $allowed = array();
20✔
36
            } else {
4✔
37
                $allowed = array_intersect_key($allowedRel, static::$values);
170✔
38
            }
39
            $this->allowed = $allowed;
190✔
40
        }
38✔
41

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

45
        $result = array();
190✔
46
        foreach ($parts as $part) {
190✔
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));
190✔
50
            if (!isset($this->allowed[$part])) {
190✔
51
                continue;
70✔
52
            }
53
            $result[$part] = true;
170✔
54
        }
38✔
55

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

60
        return implode(' ', array_keys($result));
170✔
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