Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong output html if table's caption contains headers #131

Open
azhidkov opened this issue Apr 10, 2017 · 1 comment
Open

Wrong output html if table's caption contains headers #131

azhidkov opened this issue Apr 10, 2017 · 1 comment

Comments

@azhidkov
Copy link

azhidkov commented Apr 10, 2017

Hello, on this example HTMLPurifier 4.9.2 returns bad output html:

$text = '<table border="1" style="width:300px">
    <caption>
        <h2><strong>caption</strong></h2>
    </caption>
    <tbody>
        <tr>
            <td style="width:64px;text-align:right"><strong>Life:</strong></td>
            <td style="width:80px"><strong>063-560-10-10</strong></td>
        </tr>
        <tr>
            <td style="width:64px;text-align:right"><strong>Skype:</strong></td>
            <td style="width:80px"><strong>saleusa</strong></td>
        </tr>
        <tr>
            <td style="width:64px;text-align:right"><strong>Viber:</strong></td>
            <td style="width:80px"><strong>0973151111</strong></td>
        </tr>
        <tr>
            <td style="width:64px;text-align:right"><strong>e-mail:</strong></td>
            <td style="width:80px"><strong>info@saleusa.com</strong></td>
        </tr>
    </tbody>
</table>
';

$config = HTMLPurifier_Config::createDefault();
$p = new HTMLPurifier($config);
$html = $p->purify($text);

Output html is:

<h2><strong>caption</strong></h2>
    
    <strong>Life:</strong>
            <strong>063-560-10-10</strong>
        <strong>Skype:</strong>
            <strong>saleusa</strong>
        <strong>Viber:</strong>
            <strong>0973151111</strong>
        <strong>e-mail:</strong>
            <strong>info@saleusa.com</strong>

But if I remove h2 tag (change caption to <strong>caption</strong>) everything OK.
Is this a bug or may be I just not turn on some settings?

@ezyang
Copy link
Owner

ezyang commented Apr 12, 2017

In HTML 4.01, the contents of caption must be inline elements; h2 is a block element so it can't be allowed.

As for why we lose all of the table structure, I haven't investigated closely, but I suspect what may be happening is that h2 is triggering us to insert closing tags for the table. The subsequent open/close table tags are then dropped as not valid and then you lose the formatting.

There might be an easy hack to work around this particular case but I am not sure what a general fix might be. Perhaps try setting Core.LexerImpl to PH5P?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants