cloudflare / cloudflare/lol-html

Can't add custom attribute to <desc> element

Open
#86 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2.1k
Forks
111
PR merge metrics
No merged PRs in 30d

Description

AFAIU, this parser is what `HTMLRewriter` in CloudFlare workers uses under the hood.
I have a simple worker which transforms the HTML received as request body and adds a new attribute to each node. It seems that there is a bug, and the attribute change is not applied to `` element.

Example:

```js
class EnumerationElementHandler {
constructor() {
this.counter = 0;
}
element(element) {
const c = this.counter++;
element.setAttribute('data-custom', c.toString())
}
}

const rewriter = new HTMLRewriter().on("*", new EnumerationElementHandler())

export default {
async fetch(request) {
return rewriter.transform(new Response(request.body, {status: 200}));
},
};
```

Now, I send a POST request with the following body:

```html


```

Output:

```html


```

As you can see, `data-custom` attribute is added to every node but ``.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the HTMLRewriter example with the SVG containing a element, then trace the parser's handling of SVG elements and attribute callbacks. Done means the custom attribute is applied to as it is to the surrounding elements, with regression coverage for this input.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rust
Domain
backend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.