• 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

96.2
/library/HTMLPurifier/HTML5Config.php
1
<?php
2

3
class HTMLPurifier_HTML5Config extends HTMLPurifier_Config
4
{
5
    const REVISION = 2022080702;
6

7
    /**
8
     * @param  string|array|HTMLPurifier_Config $config
9
     * @param  HTMLPurifier_ConfigSchema $schema OPTIONAL
10
     * @return HTMLPurifier_HTML5Config
11
     */
12
    public static function create($config, $schema = null)
13
    {
14
        if ($config instanceof HTMLPurifier_Config) {
14,292✔
15
            $schema = $config->def;
12✔
16
            $config = null;
12✔
17
        }
2✔
18

19
        if (!$schema instanceof HTMLPurifier_ConfigSchema) {
14,292✔
20
            $schema = HTMLPurifier_ConfigSchema::instance();
14,292✔
21
        }
2,382✔
22

23
        $configObj = new self($schema);
14,292✔
24
        $configObj->set('HTML.DefinitionID', __CLASS__);
14,292✔
25
        $configObj->set('HTML.DefinitionRev', self::REVISION);
14,292✔
26

27
        $configObj->set('URI.DefinitionID', __CLASS__);
14,292✔
28
        $configObj->set('URI.DefinitionRev', self::REVISION);
14,292✔
29

30
        if (is_string($config)) {
14,292✔
31
            $configObj->loadIni($config);
12✔
32

33
        } elseif (is_array($config)) {
14,282✔
34
            $configObj->loadArray($config);
24✔
35
        }
4✔
36

37
        return $configObj;
14,292✔
38
    }
39

40
    /**
41
     * Creates a configuration object using the default config schema instance
42
     *
43
     * @return HTMLPurifier_HTML5Config
44
     */
45
    public static function createDefault()
46
    {
47
        return self::create(null);
168✔
48
    }
49

50
    /**
51
     * Creates a new config object that inherits from a previous one
52
     *
53
     * @param  HTMLPurifier_Config $config
54
     * @return HTMLPurifier_HTML5Config
55
     */
56
    public static function inherit(HTMLPurifier_Config $config)
57
    {
58
        return new self($config->def, $config->plist);
12✔
59
    }
60

61
    /**
62
     * @param HTMLPurifier_ConfigSchema $schema
63
     * @param HTMLPurifier_PropertyList|null $parent OPTIONAL
64
     */
65
    public function __construct(HTMLPurifier_ConfigSchema $schema, $parent = null)
66
    {
67
        if ($parent && !$parent instanceof HTMLPurifier_PropertyList) {
14,304✔
NEW
68
            throw new InvalidArgumentException(
×
NEW
69
                'Argument #2 ($parent) passed to ' . __METHOD__ . '() must be an instance of HTMLPurifier_PropertyList or null'
×
NEW
70
            );
71
        }
72

73
        // ensure 'HTML5' is among allowed 'HTML.Doctype' values
74
        $doctypeConfig = $schema->info['HTML.Doctype'];
14,304✔
75

76
        if (empty($doctypeConfig->allowed['HTML5'])) {
14,304✔
77
            $allowed = array_merge($doctypeConfig->allowed, array('HTML5' => true));
12✔
78
            $schema->addAllowedValues('HTML.Doctype', $allowed);
12✔
79
        }
2✔
80

81
        if (empty($schema->info['HTML.IframeAllowFullscreen'])) {
14,304✔
82
            $schema->add('HTML.IframeAllowFullscreen', false, 'bool', false);
12✔
83
        }
2✔
84

85
        if (empty($schema->info['HTML.Forms'])) {
14,304✔
86
            $schema->add('HTML.Forms', false, 'bool', false);
×
87
        }
88

89
        if (empty($schema->info['HTML.Link'])) {
14,304✔
90
            $schema->add('HTML.Link', false, 'bool', false);
12✔
91
        }
2✔
92

93
        if (empty($schema->info['HTML.SafeLink'])) {
14,304✔
94
            $schema->add('HTML.SafeLink', false, 'bool', false);
12✔
95
        }
2✔
96

97
        if (empty($schema->info['URI.SafeLinkRegexp'])) {
14,304✔
98
            $schema->add('URI.SafeLinkRegexp', null, 'string', true);
12✔
99
        }
2✔
100

101
        if (empty($schema->info['Attr.AllowedInputTypes'])) {
14,304✔
102
            $schema->add('Attr.AllowedInputTypes', null, 'lookup', true);
12✔
103
        }
2✔
104

105
        // HTMLPurifier doesn't define %CSS.DefinitionID, but it's required for
106
        // customizing CSS definition object (in the future)
107
        if (empty($schema->info['CSS.DefinitionID'])) {
14,304✔
108
            $schema->add('CSS.DefinitionID', null, 'string', true);
12✔
109
        }
2✔
110

111
        parent::__construct($schema, $parent);
14,304✔
112

113
        // Set up defaults for AutoFormat.RemoveEmpty.Predicate to properly handle
114
        // empty video and audio elements.
115
        if (!$this->plist->has('AutoFormat.RemoveEmpty.Predicate')) {
14,304✔
116
            $this->set('AutoFormat.RemoveEmpty.Predicate', array_merge(
14,304✔
117
                $schema->defaults['AutoFormat.RemoveEmpty.Predicate'],
14,304✔
118
                array(
8,344✔
119
                    'video' => array(),
14,304✔
120
                    'audio' => array(),
10,728✔
121
                )
8,344✔
122
            ));
10,728✔
123
        }
2,384✔
124

125
        $this->set('HTML.Doctype', 'HTML5');
14,304✔
126
        $this->set('HTML.XHTML', false);
14,304✔
127
        $this->set('Attr.ID.HTML5', true);
14,304✔
128
        $this->set('Output.CommentScriptContents', false);
14,304✔
129
    }
5,960✔
130

131
    public function getDefinition($type, $raw = false, $optimized = false)
132
    {
133
        // Setting HTML.* keys removes any previously instantiated HTML
134
        // definition object, so set up HTML5 definition as late as possible
135
        if ($type === 'HTML' && empty($this->definitions[$type])) {
10,332✔
136
            if ($def = parent::getDefinition($type, true, true)) {
10,332✔
137
                /** @var HTMLPurifier_HTMLDefinition $def */
138
                HTMLPurifier_HTML5Definition::setupHTMLDefinition($def, $this);
10,332✔
139
            }
1,722✔
140
        }
1,722✔
141

142
        if ($type === 'URI' && empty($this->definitions[$type])) {
10,332✔
143
            if ($def = parent::getDefinition($type, true, true)) {
1,164✔
144
                /** @var HTMLPurifier_URIDefinition $def */
145
                HTMLPurifier_HTML5URIDefinition::setupDefinition($def, $this);
1,164✔
146
            }
194✔
147
        }
194✔
148

149
        return parent::getDefinition($type, $raw, $optimized);
10,332✔
150
    }
151

152
    public function set($key, $value, $a = null)
153
    {
154
        // Special case for HTML5 lexer, so that it can be specified as a string,
155
        // just like the other lexers ('DOMLex', 'DirectLex' and 'PH5P')
156
        if ($key === 'Core.LexerImpl' && $value === 'HTML5') {
14,304✔
157
            $value = new HTMLPurifier_Lexer_HTML5();
12✔
158
        }
2✔
159
        parent::set($key, $value, $a);
14,304✔
160
    }
5,960✔
161
}
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

© 2025 Coveralls, Inc