ezyang / ezyang/htmlpurifier

Undefined property: Illuminate\Support\Number::$required

Open
#431 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
3.4k
Forks
361
Avg merge
3d 41m
Merged PRs (30d)
2

Description

Using Laravel 11.36.1 with PHP 8.3, mews/purifier 3.4.2 and the latest version of ezyang/htmlpurifier.

When validating Number custom attributes, I get the following exception when i want to purify this string:

<p>Test</p>

This is the exception trace:

{
    "message": "Undefined property: Illuminate\\Support\\Number::$required",
    "exception": "ErrorException",
    "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php",
    "line": 129,
    "trace": [
        {
            "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php",
            "line": 290,
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php",
            "line": 129,
            "function": "Illuminate\\Foundation\\Bootstrap\\{closure}",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/HTMLModuleManager.php",
            "line": 437,
            "function": "expandIdentifiers",
            "class": "HTMLPurifier_AttrCollections",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/HTMLModuleManager.php",
            "line": 361,
            "function": "getElement",
            "class": "HTMLPurifier_HTMLModuleManager",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/HTMLDefinition.php",
            "line": 253,
            "function": "getElements",
            "class": "HTMLPurifier_HTMLModuleManager",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/HTMLDefinition.php",
            "line": 195,
            "function": "processModules",
            "class": "HTMLPurifier_HTMLDefinition",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Definition.php",
            "line": 51,
            "function": "doSetup",
            "class": "HTMLPurifier_HTMLDefinition",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Config.php",
            "line": 497,
            "function": "setup",
            "class": "HTMLPurifier_Definition",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Config.php",
            "line": 415,
            "function": "getDefinition",
            "class": "HTMLPurifier_Config",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Generator.php",
            "line": 74,
            "function": "getHTMLDefinition",
            "class": "HTMLPurifier_Config",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier.php",
            "line": 158,
            "function": "__construct",
            "class": "HTMLPurifier_Generator",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/mews/purifier/src/Purifier.php",
            "line": 290,
            "function": "purify",
            "class": "HTMLPurifier",
            "type": "->"
        },
        // rest is omitted for clairty

Config:

return [
    'encoding' => 'UTF-8',
    'finalize' => true,
    'ignoreNonStrings' => false,
    'cachePath' => storage_path('app/purifier'),
    'cacheFileMode' => 0755,
    'settings' => [
        'default' => [
            'HTML.Doctype' => 'HTML 4.01 Transitional',
            'HTML.Allowed' => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style|data-mention|data-mention-user-id|data-mention-user-type],h1,h2,h3',
            'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
            'AutoFormat.AutoParagraph' => true,
            'AutoFormat.RemoveEmpty' => true,
        ],
        'custom_config_note' => [
            'HTML.Allowed' => 'div,b,strong,i,a[href|title],ul,ol,li,p,br,span[style|data-mention|data-mention-user-id|data-mention-user-type]',
            'AutoFormat.AutoParagraph' => true,
            'AutoFormat.RemoveEmpty' => true,
        ],
        'custom_config_svg_overlay' => [
            'HTML.Allowed' => 'svg,path[d|fill],circle[cx|cy|r|fill],rect[x|y|rx|ry|width|height]',
        ],
        'test' => [
            'Attr.EnableID' => 'true',
        ],
        "youtube" => [
            "HTML.SafeIframe" => 'true',
            "URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
        ],
        'custom_definition' => [
            'id' => 'html5-definitions',
            'rev' => 1,
            'debug' => false,
            'elements' => [
                // http://developers.whatwg.org/sections.html
                ['section', 'Block', 'Flow', 'Common'],
                ['nav', 'Block', 'Flow', 'Common'],
                ['article', 'Block', 'Flow', 'Common'],
                ['aside', 'Block', 'Flow', 'Common'],
                ['header', 'Block', 'Flow', 'Common'],
                ['footer', 'Block', 'Flow', 'Common'],

                // Content model actually excludes several tags, not modelled here
                ['address', 'Block', 'Flow', 'Common'],
                ['hgroup', 'Block', 'Required: h1 | h2 | h3 | h4 | h5 | h6', 'Common'],

                // http://developers.whatwg.org/grouping-content.html
                ['figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common'],
                ['figcaption', 'Inline', 'Flow', 'Common'],

                // http://developers.whatwg.org/the-video-element.html#the-video-element
                ['video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
                    'src' => 'URI',
                    'type' => 'Text',
                    'width' => 'Length',
                    'height' => 'Length',
                    'poster' => 'URI',
                    'preload' => 'Enum#auto,metadata,none',
                    'controls' => 'Bool',
                ]],
                ['source', 'Block', 'Flow', 'Common', [
                    'src' => 'URI',
                    'type' => 'Text',
                ]],

                // http://developers.whatwg.org/text-level-semantics.html
                ['s', 'Inline', 'Inline', 'Common'],
                ['var', 'Inline', 'Inline', 'Common'],
                ['sub', 'Inline', 'Inline', 'Common'],
                ['sup', 'Inline', 'Inline', 'Common'],
                ['mark', 'Inline', 'Inline', 'Common'],
                ['wbr', 'Inline', 'Empty', 'Core'],

                // http://developers.whatwg.org/edits.html
                ['ins', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']],
                ['del', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']],
            ],
            'attributes' => [
                ['iframe', 'allowfullscreen', 'Bool'],
                ['table', 'height', 'Text'],
                ['td', 'border', 'Text'],
                ['th', 'border', 'Text'],
                ['tr', 'width', 'Text'],
                ['tr', 'height', 'Text'],
                ['tr', 'border', 'Text'],
            ],
        ],
        'custom_attributes' => [
            ['a', 'target', 'Enum#_blank,_self,_target,_top'],

            // SVG <path> element attributes
            ['path', 'd', 'Text'],
            ['path', 'fill', 'Color'],

            // SVG <circle> element attributes
            ['circle', 'cx', 'Number'],
            ['circle', 'cy', 'Number'],
            ['circle', 'r', 'Number'],
            ['circle', 'fill', 'Color'],

            // SVG <rect> element attributes
            ['rect', 'rx', 'Number'],
            ['rect', 'ry', 'Number'],
            ['rect', 'x', 'Number'],
            ['rect', 'y', 'Number'],
            ['rect', 'width', 'Number'],
            ['rect', 'height', 'Number'],
            ['rect', 'pathLength', 'Number'],
            ['rect', 'fill', 'Color'],

            // CKEditor Mentions
            ['span', 'data-mention', 'Text'],
            ['span', 'data-mention-user-id', 'Text'],
            ['span', 'data-mention-user-type', 'Text'],
        ],
        'custom_elements' => [
            ['u', 'Inline', 'Inline', 'Common'],

            // SVG <path> element
            ['path', 'Inline', 'Empty', 'Common'],

            // SVG <circle> element
            ['circle', 'Inline', 'Empty', 'Common'],

            // SVG <rect> element
            ['rect', 'Inline', 'Empty', 'Common'],
        ],
    ],
];

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown custom_attributes Number configuration and the

Test

input. Start at vendor/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php line 129, then follow the HTMLPurifier_HTMLModuleManager.php calls; done means purification completes without the Undefined property exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
backend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.