• 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/InputType.php
1
<?php
2

3
class HTMLPurifier_AttrDef_HTML5_InputType extends HTMLPurifier_AttrDef
4
{
5
    /**
6
     * Lookup table for valid values
7
     * @var array
8
     * @see https://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_extformsmodule
9
     */
10
    protected static $values = array(
11
        'button' => true,
12
        'checkbox' => true,
13
        'file' => true,
14
        'hidden' => true,
15
        'image' => true,
16
        'password' => true,
17
        'radio' => true,
18
        'reset' => true,
19
        'submit' => true,
20
        'text' => true,
21
    );
22

23
    /**
24
     * Lookup for input types allowed in current configuration
25
     * @var array
26
     */
27
    protected $allowed;
28

29
    protected $allowedFromConfig;
30

31
    protected function setupAllowed(HTMLPurifier_Config $config)
32
    {
33
        $allowedFromConfig = isset($config->def->info['Attr.AllowedInputTypes'])
540✔
34
            ? $config->get('Attr.AllowedInputTypes')
540✔
35
            : null;
378✔
36

37
        // Check if current allowed value is based on the latest value from config.
38
        // Comparing with '===' shouldn't be a performance bottleneck, because the
39
        // value retrieved from the config is never changed after being stored.
40
        // PHP's copy-on-write mechanism prevents making unnecessary array copies,
41
        // allowing this particular array comparison to be made in O(1) time, when
42
        // the corresponding value in config hasn't changed, and in O(n) time after
43
        // each change.
44
        if ($this->allowed !== null && $this->allowedFromConfig === $allowedFromConfig) {
540✔
45
            return;
80✔
46
        }
47

48
        if (is_array($allowedFromConfig)) {
540✔
49
            $allowed = array_intersect_key($allowedFromConfig, self::$values);
40✔
50
        } else {
8✔
51
            $allowed = self::$values;
510✔
52
        }
53

54
        $this->allowed = $allowed;
540✔
55
        $this->allowedFromConfig = $allowedFromConfig;
540✔
56
    }
270✔
57

58
    /**
59
     * @param string $string
60
     * @param HTMLPurifier_Config $config
61
     * @param HTMLPurifier_Context $context
62
     * @return bool|string
63
     */
64
    public function validate($string, $config, $context)
65
    {
66
        $this->setupAllowed($config);
540✔
67
        $value = strtolower($this->parseCDATA($string));
540✔
68

69
        if (!isset(self::$values[$value])) {
540✔
70
            return false;
50✔
71
        }
72

73
        if (!isset($this->allowed[$value])) {
510✔
74
            return false;
40✔
75
        }
76

77
        return $value;
490✔
78
    }
79
}
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