cloudflare / cloudflare/lol-html
Can't add custom attribute to <desc> element
- 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
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