• 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

98.68
/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) {
11,910✔
15
            $schema = $config->def;
10✔
16
            $config = null;
10✔
17
        }
2✔
18

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

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

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

30
        if (is_string($config)) {
11,910✔
31
            $configObj->loadIni($config);
10✔
32

33
        } elseif (is_array($config)) {
11,902✔
34
            $configObj->loadArray($config);
20✔
35
        }
4✔
36

37
        return $configObj;
11,910✔
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);
140✔
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);
10✔
59
    }
60

61
    /**
62
     * @param HTMLPurifier_ConfigSchema $schema
63
     * @param HTMLPurifier_PropertyList $parent OPTIONAL
64
     */
65
    public function __construct(HTMLPurifier_ConfigSchema $schema, HTMLPurifier_PropertyList $parent = null)
66
    {
67
        // ensure 'HTML5' is among allowed 'HTML.Doctype' values
68
        $doctypeConfig = $schema->info['HTML.Doctype'];
11,920✔
69

70
        if (empty($doctypeConfig->allowed['HTML5'])) {
11,920✔
71
            $allowed = array_merge($doctypeConfig->allowed, array('HTML5' => true));
10✔
72
            $schema->addAllowedValues('HTML.Doctype', $allowed);
10✔
73
        }
2✔
74

75
        if (empty($schema->info['HTML.IframeAllowFullscreen'])) {
11,920✔
76
            $schema->add('HTML.IframeAllowFullscreen', false, 'bool', false);
10✔
77
        }
2✔
78

79
        if (empty($schema->info['HTML.Forms'])) {
11,920✔
80
            $schema->add('HTML.Forms', false, 'bool', false);
×
81
        }
82

83
        if (empty($schema->info['HTML.Link'])) {
11,920✔
84
            $schema->add('HTML.Link', false, 'bool', false);
10✔
85
        }
2✔
86

87
        if (empty($schema->info['HTML.SafeLink'])) {
11,920✔
88
            $schema->add('HTML.SafeLink', false, 'bool', false);
10✔
89
        }
2✔
90

91
        if (empty($schema->info['URI.SafeLinkRegexp'])) {
11,920✔
92
            $schema->add('URI.SafeLinkRegexp', null, 'string', true);
10✔
93
        }
2✔
94

95
        if (empty($schema->info['Attr.AllowedInputTypes'])) {
11,920✔
96
            $schema->add('Attr.AllowedInputTypes', null, 'lookup', true);
10✔
97
        }
2✔
98

99
        // HTMLPurifier doesn't define %CSS.DefinitionID, but it's required for
100
        // customizing CSS definition object (in the future)
101
        if (empty($schema->info['CSS.DefinitionID'])) {
11,920✔
102
            $schema->add('CSS.DefinitionID', null, 'string', true);
10✔
103
        }
2✔
104

105
        parent::__construct($schema, $parent);
11,920✔
106

107
        // Set up defaults for AutoFormat.RemoveEmpty.Predicate to properly handle
108
        // empty video and audio elements.
109
        if (!$this->plist->has('AutoFormat.RemoveEmpty.Predicate')) {
11,920✔
110
            $this->set('AutoFormat.RemoveEmpty.Predicate', array_merge(
11,920✔
111
                $schema->defaults['AutoFormat.RemoveEmpty.Predicate'],
11,920✔
112
                array(
5,960✔
113
                    'video' => array(),
11,920✔
114
                    'audio' => array(),
8,344✔
115
                )
5,960✔
116
            ));
8,344✔
117
        }
2,384✔
118

119
        $this->set('HTML.Doctype', 'HTML5');
11,920✔
120
        $this->set('HTML.XHTML', false);
11,920✔
121
        $this->set('Attr.ID.HTML5', true);
11,920✔
122
        $this->set('Output.CommentScriptContents', false);
11,920✔
123
    }
5,960✔
124

125
    public function getDefinition($type, $raw = false, $optimized = false)
126
    {
127
        // Setting HTML.* keys removes any previously instantiated HTML
128
        // definition object, so set up HTML5 definition as late as possible
129
        if ($type === 'HTML' && empty($this->definitions[$type])) {
8,610✔
130
            if ($def = parent::getDefinition($type, true, true)) {
8,610✔
131
                /** @var HTMLPurifier_HTMLDefinition $def */
132
                HTMLPurifier_HTML5Definition::setupHTMLDefinition($def, $this);
8,610✔
133
            }
1,722✔
134
        }
1,722✔
135

136
        if ($type === 'URI' && empty($this->definitions[$type])) {
8,610✔
137
            if ($def = parent::getDefinition($type, true, true)) {
970✔
138
                /** @var HTMLPurifier_URIDefinition $def */
139
                HTMLPurifier_HTML5URIDefinition::setupDefinition($def, $this);
970✔
140
            }
194✔
141
        }
194✔
142

143
        return parent::getDefinition($type, $raw, $optimized);
8,610✔
144
    }
145

146
    public function set($key, $value, $a = null)
147
    {
148
        // Special case for HTML5 lexer, so that it can be specified as a string,
149
        // just like the other lexers ('DOMLex', 'DirectLex' and 'PH5P')
150
        if ($key === 'Core.LexerImpl' && $value === 'HTML5') {
11,920✔
151
            $value = new HTMLPurifier_Lexer_HTML5();
10✔
152
        }
2✔
153
        parent::set($key, $value, $a);
11,920✔
154
    }
5,960✔
155
}
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