Repository navigation
fix: coerce non-string innerHTML/innerText values - #359
Open
johnhldiver-beep wants to merge 1 commit into
Open
johnhldiver-beep wants to merge 1 commit into
johnhldiver-beep wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #308.
Setting
Element.innerHTMLorinnerTextto 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→ readinglengthof null/undefined;innerTexthad 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, sonull → ''and everything else isString(value)(includingundefined → "undefined"). This single function backs the Element setter, the ShadowRoot setter, and the outerHTML path, so all are fixed. TheStringimport uses the repo's existing alias pattern fromshared/utils.js.esm/interface/element.js(+cjs/mirror): newset innerTextwith the same coercion, replacing children liketextContentdoes. Theget innerTextwhitespace rules are untouched.style/textelement own setters deliberately left alone — they route throughtextContent+Textcoercion and do not throw on the same inputs (verified:style.innerHTML=1→"1",null→"", etc.).Tests: regression tests in
test/html/element.jsforinnerHTML = 1/null/undefined,innerText = 1/null, plus a normal-string sanity case. New tests failed before the fix (element test exit 1 with the expectedbuffers[0].sliceTypeError);node test/html/element.jsand the fullnode test/index.jssuite 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.