cloudflare / cloudflare/lol-html

Implied End Tags not Handled Correctly

Open
#110 7 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
2.1k
Forks
111
PR merge metrics
No merged PRs in 30d

Description

While working on #109 I noticed that one can create a bit of an odd situation when trying to rewrite tags in the presence of optional end tags.

Take this list:

```html


  • a
  • b

```

When I select `li` and change the tag to `div` I end up with the following output:

```html


    a
    b

    ```

    This tests shows the issue

    ```rust

    #[test]
    fn optional_end_tags() {
    let output = rewrite_element(b"

    • a
    • b
    ", UTF_8, "li", |el| {
    el.set_tag_name("div").unwrap();
    });
    assert_eq!(output, "
      a
      b
    ");
    }
    ```

    I believe the system would need to emit "virtual" end tags for when implicitly closed tags are encountered. I believe the system also does not handle this tag stack correctly otherwise which probably should confuse the css selector as well.

Contributor guide

Open the contributing guide

Research direction

Start with the optional_end_tags test and the rewrite_element call shown in the issue, then inspect how the tag stack handles implicitly closed li elements and how CSS selection sees them. Done means rewriting li to div produces correctly balanced output while preserving the surrounding ul structure and the test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.