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

3
/**
4
 * Validates a floating point number
5
 */
6
class HTMLPurifier_AttrDef_HTML5_Float extends HTMLPurifier_AttrDef
7
{
8
    /**
9
     * @var int|float
10
     */
11
    protected $min;
12

13
    /**
14
     * @var int|float
15
     */
16
    protected $max;
17

18
    /**
19
     * @var bool
20
     */
21
    protected $minInclusive = true;
22

23
    /**
24
     * @var bool
25
     */
26
    protected $maxInclusive = true;
27

28
    /**
29
     * Supported options:
30
     *
31
     * - 'min'          => int|float
32
     * - 'max'          => int|float
33
     * - 'minInclusive' => bool
34
     * - 'maxInclusive' => bool
35
     *
36
     * @param array $options OPTIONAL
37
     */
38
    public function __construct($options = null)
39
    {
40
        $options = is_array($options) ? $options : array();
8,640✔
41

42
        $this->min = isset($options['min']) ? floatval($options['min']) : null;
8,640✔
43
        $this->max = isset($options['max']) ? floatval($options['max']) : null;
8,640✔
44

45
        if (isset($options['minInclusive'])) {
8,640✔
46
            $this->minInclusive = (bool) $options['minInclusive'];
8,630✔
47
        }
1,726✔
48

49
        if (isset($options['maxInclusive'])) {
8,640✔
50
            $this->maxInclusive = (bool) $options['maxInclusive'];
20✔
51
        }
4✔
52
    }
4,320✔
53

54
    /**
55
     * @param string $number
56
     * @param HTMLPurifier_Config $config
57
     * @param HTMLPurifier_Context $context
58
     * @return bool|string
59
     */
60
    public function validate($number, $config, $context)
61
    {
62
        $number = $this->parseCDATA($number);
190✔
63

64
        if ($number === '') {
190✔
65
            return false;
10✔
66
        }
67

68
        // Up to PHP 5.6 is_numeric() returns TRUE for hex strings
69
        // http://php.net/manual/en/function.is-numeric.php
70
        if (!preg_match('/^[-+.0-9Ee]+$/', $number) || !is_numeric($number)) {
190✔
71
            return false;
20✔
72
        }
73

74
        // HTML numbers cannot start with '+' character
75
        // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-floating-point-number
76
        if (substr($number, 0, 1) === '+') {
180✔
77
            $number = substr($number, 1);
10✔
78
        }
2✔
79

80
        $value = floatval($number);
180✔
81

82
        if (($this->min !== null) &&
180✔
83
            (($this->minInclusive && $value < $this->min) || (!$this->minInclusive && $value <= $this->min))
178✔
84
        ) {
36✔
85
            return false;
20✔
86
        }
87

88
        if (($this->max !== null) &&
170✔
89
            (($this->maxInclusive && $this->max < $value) || (!$this->maxInclusive && $this->max <= $value))
138✔
90
        ) {
34✔
91
            return false;
10✔
92
        }
93

94
        return $number;
170✔
95
    }
96

97
    /**
98
     * Factory function
99
     *
100
     * @param string $string A comma-delimited list of key:value pairs. Example: "min:0,max:10".
101
     * @return HTMLPurifier_AttrDef_HTML5_Float
102
     */
103
    public function make($string)
104
    {
105
        $options = array();
10✔
106
        foreach (explode(',', $string) as $pair) {
10✔
107
            $parts = explode(':', $pair, 2);
10✔
108
            if (count($parts) === 2) {
10✔
109
                list($key, $value) = $parts;
10✔
110
                $options[$key] = $value;
10✔
111
            }
2✔
112
        }
2✔
113
        $class = get_class($this);
10✔
114
        return new $class($options);
10✔
115
    }
116
}
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