preactjs / preactjs/preact-render-to-string

HTML_LOWER_CASE regex incorrectly lowercases custom element properties

Open
#451 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
726
Forks
101
Avg merge
3d 6h
Merged PRs (30d)
6

Description

Bug

The HTML_LOWER_CASE regex used to determine which attributes should be lowercased
can falsely match custom element properties. For example, passing channelId to a
custom element results in channelid because the regex matches the ch prefix
(intended for charSet).

Reproduction

// Code
<my-fragment channelId="abc123" />
// Expected
<my-fragment channelId="abc123" />
// Actual
<my-fragment channelid="abc123" />

Cause

The regex ^(?:accessK|auto[A-Z]|cell|ch|col|...) uses broad prefixes that can
match unrelated property names on custom elements.

Proposed fix

Replace the regex with an explicit Set of known camelCase HTML attribute names
and use .has() instead of .test().

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the HTML_LOWER_CASE regex in the JavaScript source and reproduce the custom-element example with channelId. Replace the broad matching approach with the proposed explicit set of known camelCase HTML attributes, then verify that channelId is preserved while intended HTML attributes are still lowercased.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.