HTMLRewriter's element.setAttribute() method alters the surrounding single quote ch

I’m using the element.setAttribute() method in Cloudflare Workers’ HTMLRewriter. When attempting to set attributes for HTML elements using this method, if the attribute value is enclosed in single quotes ('), HTMLRewriter converts it to double quotes ("). This results in attribute values being enclosed in double quotes.

This issue resembles a similar bug found in cheerio, as mentioned in the cheerio repository’s issue tracker at Maintain tag attribute quote characters · Issue #720 · cheeriojs/cheerio · GitHub. In that issue, similar behavior is discussed, and gaecom proposed a solution.