cheerio icon indicating copy to clipboard operation
cheerio copied to clipboard

Issue #581 - coerce attribute names to lower case in HTML mode

Open davidfei222 opened this issue 2 years ago • 4 comments

Fix for issue #581. Attribute names will now always be coerced to lower case when attempting to get or set attributes to keep the behavior in line with how cheerio.load() handles attribute names.

davidfei222 avatar Jul 28 '23 19:07 davidfei222

This PR updates Cheerio's .attr() functionality to more closely match jQuery's .attr(), which saves and retrieves attributes by lowercasing the input name.

walshyb avatar Jul 28 '23 19:07 walshyb

Adjusted a few existing tests to be able to support tests for this fix.

rjpatt avatar Jul 28 '23 20:07 rjpatt

Thanks a lot for this PR! Some notes:

  1. The change in the fixture led to a need for quite a few unrelated changes. Please use one of the other fixtures or add a new one.
  2. Cheerio has an XML mode for working with XML. XML is case-sensitive, so we don't want to lowercase tag names in XML. You will probably end up with something along the lines of
attrNameToUse = this.options.xmlMode ? attrName : attrName.toLowerCase()

fb55 avatar Jul 29 '23 08:07 fb55

@fb55 Apologies for the late response - my colleagues and I have been very busy at work recently. The requested changes have been made - please re-review at your earliest convenience. Thanks!

davidfei222 avatar Aug 17 '23 21:08 davidfei222