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

xemlock / htmlpurifier-html5 / 13179144986

06 Feb 2025 12:48PM UTC coverage: 99.276% (-0.1%) from 99.406%
13179144986

Pull #84

github

web-flow
Merge b3671842e into 15fcb5aa0
Pull Request #84: PHP 8.4 support

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

2 existing lines in 2 files now uncovered.

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/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'])
648✔
34
            ? $config->get('Attr.AllowedInputTypes')
648✔
UNCOV
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) {
648✔
45
            return;
96✔
46
        }
47

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

54
        $this->allowed = $allowed;
648✔
55
        $this->allowedFromConfig = $allowedFromConfig;
648✔
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);
648✔
67
        $value = strtolower($this->parseCDATA($string));
648✔
68

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

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

77
        return $value;
588✔
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