ezyang / ezyang/htmlpurifier

MakeWellFormed strategy when attempting to fix invalid markup messes it up even more

Open
#258 1 comment 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

MakeWellFormed strategy when attempting to fix invalid markup messes it up even more. Please consider the following test script:

<?php
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
echo $purifier->purify('<p><i><ul><li>text</li></ul></i></p>');

one would expect the output:

<p><i></i></p><ul><li>text</li></ul>

or ideally:

<p><i></i></p><ul><li><i>text</i></li></ul>

Instead we get:

<p><i></i></p><i>text</i>

Tested against HTMLPurifier 4.12.0.

By doing some digging I found that setting $formatting property to false on <i> element definition in the Presentation module helps a little - the <ul> structure is retained. The drawback of this is that the carrying <i> element no longer works.

This suggests that the tree-fixing algorithm in HTMLPurifier_Strategy_MakeWellFormed::execute() requires some tuning.

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

Start with the provided PHP reproduction and inspect HTMLPurifier_Strategy_MakeWellFormed::execute() around the linked location. Compare its handling of the nested p, i, ul, and li elements with the behavior of the formatting property in HTMLPurifier/HTMLModule/Presentation.php. Done means preserving the ul/li structure and producing one of the expected corrected outputs, with a regression test for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.