Title: id(web/editor): image parseDOM bare Number() lets NaN/fraction/hex dimensions through — pasted image sizing silently lost or reinterpreted on save · Issue #2010 · developing-today/code · GitHub
Open Graph Title: id(web/editor): image parseDOM bare Number() lets NaN/fraction/hex dimensions through — pasted image sizing silently lost or reinterpreted on save · Issue #2010 · developing-today/code
X Title: id(web/editor): image parseDOM bare Number() lets NaN/fraction/hex dimensions through — pasted image sizing silently lost or reinterpreted on save · Issue #2010 · developing-today/code
Description: Problem In the id web editor, the image node's parseDOM converts the width/height attributes with a bare Number() and the attrs declare no validation, so non-integer dimensions are stored verbatim and then silently dropped (or reinterpre...
Open Graph Description: Problem In the id web editor, the image node's parseDOM converts the width/height attributes with a bare Number() and the attrs declare no validation, so non-integer dimensions are stored verbatim ...
X Description: Problem In the id web editor, the image node's parseDOM converts the width/height attributes with a bare Number() and the attrs declare no validation, so non-integer dimensions are stored verba...
Opengraph URL: https://github.com/developing-today/code/issues/2010
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"id(web/editor): image parseDOM bare Number() lets NaN/fraction/hex dimensions through — pasted image sizing silently lost or reinterpreted on save","articleBody":"## Problem\n\nIn the `id` web editor, the image node's `parseDOM` converts the `width`/`height` attributes with a bare `Number()` and the attrs declare no validation, so non-integer dimensions are stored verbatim and then silently dropped (or reinterpreted) downstream:\n\n- `pkgs/id/web/src/editor.ts:145-146` — `width: el.getAttribute(\"width\") ? Number(el.getAttribute(\"width\")) : null` (same for `height`). The image attrs at `editor.ts:125-126` are `{ default: null }` with no `validate`, unlike `ordered_list`'s `order` which at least declares `validate: \"number\"` (and still lets NaN through — #2005).\n- `pkgs/id/web/src/editor.ts:157-158` — `toDOM` emits the attr only `if (node.attrs.width)`: `NaN` and `0` are falsy, so they vanish; a fraction (`2.5`) or negative (`-5`) is emitted as the invalid attribute `width=\"2.5\"` / `width=\"-5\"`.\n- `pkgs/id/src/web/markdown.rs:1953-1954` — on save, `json[\"attrs\"][\"width\"].as_u64()` is `None` for a fraction, a negative, and for `NaN` (which serialises to JSON `null`), so the dimension is dropped from the saved markdown with no error. The Rust-side HTML parse (`markdown.rs:1208-1215`) accepts only a pure `u64`, so the editor is the permissive side of an asymmetric pair.\n- `pkgs/id/web/src/image-node-view.ts:58-62` — the node view sets `img.style.width = `${width}px``; `NaNpx` / `-5px` are invalid and silently ignored by the browser.\n\n## Verified this run (2026-10-28, main `38f1f00f`)\n\nProbe on the laptop (`~/git/fleet/probe-2026-10-28-laneB-imgdim/`, the shipped `getAttrs` conversion copied verbatim; `editor.ts` sha256 `4340aef4…` identical on laptop and sandbox main), with the `toDOM` truthiness check and the save-side `as_u64()` semantics modelled from the shipped code:\n\n- Control `width=\"200\"` → parseDOM `200`, toDOM `\"200\"`, saved `200` ✓\n- `width=\"200px\"` → `NaN` → toDOM omits the attribute, saved `null` — dimension silently lost\n- `width=\"50%\"` → `NaN` → same silent loss\n- `width=\"2.5\"` → `2.5` → toDOM emits `width=\"2.5\"`, saved `null` — lost on save\n- `width=\"-5\"` → `-5` → toDOM emits `width=\"-5\"`, saved `null` — lost on save\n- `width=\"abc\"` → `NaN` → silently lost\n- `width=\"0x10\"` → `16` and `width=\"1e3\"` → `1000` — silently *reinterpreted* as values the author never wrote (an HTML dimension attribute is a leading-digits value, not a JS numeric literal)\n\nPasted web content is the realistic source: images in copied HTML routinely carry `width=\"200px\"`, percentage widths, or fractional/negative junk from CMS markup, and every one of those pastes loses its sizing on the next save without any signal.\n\n## Why it matters\n\nThis is the same silent-coercion class as #2005 (ordered-list `start`) in the adjacent node of the same file, but with a different failure shape: the list renumbers, the image *loses its dimensions* (or gains ones nobody typed, `0x10` → 16). The repo's own strict parsers show the intended pattern — `parseWorldSeed` (web/src/world-seed.ts, #707/#832) accepts only decimal digits, and `parseProxyPortValue` does the same for the bin proxies (#483). The image attrs are an unhardened spot the earlier passes missed.\n\n## Acceptance criteria\n\n- [ ] Image `width`/`height` from `parseDOM` are either a non-negative integer or `null`: a value that is not a plain run of decimal digits (e.g. `200px`, `50%`, `2.5`, `-5`, `abc`, `0x10`, `1e3`) never reaches the node attrs as `NaN`, a fraction, a negative, or a reinterpreted number — it is dropped to `null` at parse time (the triage-pinned contract may instead take the HTML leading-digits value, but it must be one documented behaviour, applied identically to `width` and `height`).\n- [ ] The editor-side result agrees with the save side: any dimension the editor keeps survives `markdown.rs`'s `as_u64()` round-trip, and any it drops is dropped at parse time, not discovered missing after save.\n- [ ] Regression tests (web/src/editor.test.ts or a sibling) cover at least: `\"200\"` (kept), `\"200px\"`, `\"50%\"`, `\"2.5\"`, `\"-5\"`, `\"0x10\"` — asserting the resulting attrs; existing editor tests still pass.\n- [ ] The fix is scoped to the image node (the ordered-list site is #2005's, already filed).\n\nFiled by new-issue-creator-code-b. Related: #2005 (same file, same bare-`Number()` class, ordered_list node), #893 (image parseDOM link handling).\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-29T00:28:05Z","url":"https://github.com/developing-today/code/issues/2010"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8901b849-a73c-52b2-2b5c-7f96d91138b4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B6A0:23514F:8EB527:B970DB:6B063154 |
| html-safe-nonce | df8eea0a89eb937865f4e92153ead12a80a64371606b3096042eb71dd7e992df |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkEwOjIzNTE0Rjo4RUI1Mjc6Qjk3MERCOjZCMDYzMTU0IiwidmlzaXRvcl9pZCI6Ijg4Mjg0MTUxNTY4NzE5MDE1MjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0cb54852cf1e61390280e47bb688e062aa3b457566b5c2c132e0fcfdf7e44f24 |
| hovercard-subject-tag | issue:6090117453 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/2010/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a27d768e9a3339ac14508f37379fc4acd94381171cd5ff65ff2daae9f2b2360/developing-today/code/issues/2010 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a27d768e9a3339ac14508f37379fc4acd94381171cd5ff65ff2daae9f2b2360/developing-today/code/issues/2010 |
| og:image:alt | Problem In the id web editor, the image node's parseDOM converts the width/height attributes with a bare Number() and the attrs declare no validation, so non-integer dimensions are stored verbatim ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | c3584c853cd39700ecff6e2cf8364295ffdb5313e571046c41cd2479270f7df0 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9eb3bb1597d09170a5f282cd38ae376dee1a5ec1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width