Skip to content

PHP with tidy and custom-tags #20374

Closed
Closed

Description

@franck-paul

Description

The following code:

<?php
$str = '<custom-html-element>test</custom-html-element>';

$config = [
	'custom-tags' => 'blocklevel',
];

$tidy = new \tidy();
$tidy->parseString($str, $config, 'utf8');
$tidy->cleanRepair();

$str = (string) $tidy->value;

var_dump($str);	// should be <custom-html-element>test</custom-html-element>

Resulted in this output:

test

But I expected this output instead:

<custom-html-element>test</custom-html-element>

PHP Version

PHP 8.4.14 (cli) (built: Oct 21 2025 19:23:55) (NTS)
Copyright (c) The PHP Group
Built by Homebrew
Zend Engine v4.4.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.14, Copyright (c), by Zend Technologies
    with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans

Operating System

MacOS

Activity

  1. ndossche commented on Nov 3, 2025

    @ndossche
    Member

    I'll take a look. Enum translation appears to be broken.
    As a workaround for now you can use 'custom-tags' => 1,

  2. ndossche commented on Nov 3, 2025

    @ndossche
    Member

    On first sight the following would work, but have to double check (and probably add support for the IS_LONG case):

    diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c
    index da0eb877d58..d8e762e1287 100644
    --- a/ext/tidy/tidy.c
    +++ b/ext/tidy/tidy.c
    @@ -254,10 +254,12 @@ static int _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval *value)
     			break;
     
     		case TidyInteger:
    -			lval = zval_get_long(value);
    -			if (tidyOptSetInt(doc, tidyOptGetId(opt), lval)) {
    +			str = zval_get_tmp_string(value, &tmp_str);
    +			if (tidyOptParseValue(doc, optname, ZSTR_VAL(str))) {
    +				zend_tmp_string_release(tmp_str);
     				return SUCCESS;
     			}
    +			zend_tmp_string_release(tmp_str);
     			break;
     
     		case TidyBoolean:
    
  3. self-assigned this
    on Nov 3, 2025
  4. linked a pull request that will close this issueFix GH-20374: PHP with tidy and custom-tags #20379on Nov 3, 2025
  5. added 3 commits that reference this issue on Nov 4, 2025
    fcc159b
    07aab0c
    b8e9f7c
  6. added a commit that references this issue on Nov 4, 2025
    5b5fe43
  7. franck-paul commented on Nov 4, 2025

    @franck-paul
    Author

    I'll take a look. Enum translation appears to be broken. As a workaround for now you can use 'custom-tags' => 1,

    I tried this value but the custom tag is still missing from output.

  8. ndossche commented on Nov 4, 2025

    @ndossche
    Member

    The following code:

    <?php
    $str = '<custom-html-element>test</custom-html-element>';
    
    $config = [
    	'custom-tags' => 1,//'blocklevel',
    ];
    
    $tidy = new \tidy();
    $tidy->parseString($str, $config, 'utf8');
    $tidy->cleanRepair();
    
    $str = (string) $tidy->value;
    
    var_dump($str);	// should be <custom-html-element>test</custom-html-element>

    Outputs:

    string(124) "<!DOCTYPE html>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <custom-html-element>test</custom-html-element>
    </body>
    </html>"
    

    for me.
    Does this not work for you? What libtidy version do you have installed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions