Skip to content

fix: coerce non-string innerHTML/innerText values - #359

Open
johnhldiver-beep wants to merge 1 commit into
WebReflection:mainfrom
johnhldiver-beep:fix/308-innerhtml-coerce
Open

johnhldiver-beep wants to merge 1 commit into
WebReflection:mainfrom
johnhldiver-beep:fix/308-innerhtml-coerce

Conversation

@johnhldiver-beep

Copy link
Copy Markdown

Fixes #308.

Setting Element.innerHTML or innerText to a non-string value threw instead of coercing like browsers do. Repro on base: innerHTML = 1 → this.buffers[0].slice is not a function; null/undefined → reading length of null/undefined; innerText had no setter at all (only a getter), so any assignment threw "which has only a getter".

Fix (one concern):

  • esm/mixin/inner-html.js (+ cjs/ mirror): parseFromString(..., html === null ? '' : String(html)) — WebIDL LegacyNullToEmptyString semantics, so null → '' and everything else is String(value) (including undefined → "undefined"). This single function backs the Element setter, the ShadowRoot setter, and the outerHTML path, so all are fixed. The String import uses the repo's existing alias pattern from shared/utils.js.
  • esm/interface/element.js (+ cjs/ mirror): new set innerText with the same coercion, replacing children like textContent does. The get innerText whitespace rules are untouched.
  • style/text element own setters deliberately left alone — they route through textContent + Text coercion and do not throw on the same inputs (verified: style.innerHTML=1→"1", null→"", etc.).

Tests: regression tests in test/html/element.js for innerHTML = 1/null/undefined, innerText = 1/null, plus a normal-string sanity case. New tests failed before the fix (element test exit 1 with the expected buffers[0].slice TypeError); node test/html/element.js and the full node test/index.js suite both exit 0 with no failures after the fix. Honest limits: this suite prints no numeric assertion totals, so counts are reported as exit codes + failure-grep counts; eslint/tsc/rollup were not run (devDeps deliberately skipped for disk).

Note: prior PR #333 covered the same concern but was closed unmerged because its author voluntarily withdrew it to clean a backlog (2026-09-23) — not a maintainer rejection. Its author said he was "happy to come back later with a focused change", but that was 5+ weeks ago with no refile and the issue still OPEN, so this is not a live race.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exceptions thrown when setting Element's innerHTML or innerText with non-string value

1 participant