oliver-zehentleitner / maity

clean-up: web shared helpers: byte counting that cannot throw, json-io for landing, one clipboard helper, dead exports

Sign in to report

tsk-tpm9f3ct6nnz Open

From the web clean-up audit, area 17 (tsk-hgnbapyw7hnh), read at 80647565 (findings sent to lotse, seq 125522). Line numbers are from 80647565, so re-check them on current main. #44 is a bug.

#44 Shared: UTF-8 byte counting is copied, and two copies can throw (bug/duplication).

  • Copies:
  • preferences.js:19-25
  • report.js:26-30
  • invite.js:231
  • jour-fixe-act.js:21
  • the encoder in qr.js:64-72
  • fixture copies at api.js:1285, :1369 and :3807
  • invite.js:231 and jour-fixe-act.js:21 count with encodeURIComponent(...). That throws URIError on a lone surrogate, which a paste can produce, inside an async submit handler. The result is an unhandled rejection: nothing is sent and nothing is said.
  • Size formatting is also written three times: attachments.js:33 (sizeOf, B/KB/MB), preferences.js:28 (kib) and admin-limits.js:23-26 (MiB/GiB).
  • Proposal: M.fmt.utf8Length (a code point walk, as api.js:1285 does) and M.fmt.bytes in i18n.js, used everywhere.
  • Effort S. Risk low.

#42 json-io / landing editor: landing.js has its own copy of json-io (duplication/docs drift).

  • landing.js:554-641 (jsonPart) duplicates json-io.js:21-65 (part): the same file input, export, copy, parse failure, settled/pending state and markup (details.lp-json against details.json-io).
  • The legal editor in the same file (landing.js:716) already uses M.jsonIo.part.
  • landing.json. has about 20 keys in each of 11 catalogs, mostly word for word jsonio..
  • landing.js:89 keeps its own isObject while calling M.jsonIo.isObject at :721-742.
  • json-io.js:1-6 and views.md:4774 say "both editors share one part", but three editors exist.
  • Proposal: give part() an optional load(data, io) hook (landing posts its preview there). Delete jsonPart, the duplicate keys and the local isObject copies (also auth-pages.js:23, site-io.js:28). Fix views.md.
  • Effort M. Risk low-medium: the smoke and e2e selectors on .lp-json and #lp-json follow (about 15 hits in smoke.js, 6 in e2e.py).

#43 Shared: copy to clipboard written 11 times (duplication).

  • Where: admin-users.js:114, app.js:1269, invite.js:272, join.js:412, json-io.js:41, landing.js:576, markdown.js:49, overview.js:157, placements.js:84, runners.js:179, ticker-settings.js:125.
  • Each copy has its own pair of catalog keys.
  • markdown.js:47 already has the helper copied(text) but does not export it.
  • The fallbacks differ: only invite.js selects the field when the copy fails.
  • Proposal: M.dom.copied(text) and copyButton(textOf, opts) with one key pair.
  • Effort M. Risk low: wording.

#45 handles.js / ids.js / event.js: handle and seq rules written twice, dead exports (duplication/debt).

  • handles.js:13 FORMAT repeats NAME_RULES.handle.test (dom.js:209-214). Seven views already use NAME_RULES.
  • The FORMAT and refusal exports (handles.js:92) have no caller in web/.
  • SEQ_MAX is defined at both ids.js:37 and event.js:20.
  • M.event = {placeOf, seqOf} (event.js:83) has no caller in web/js or web/tools.
  • Proposal: handles.js uses NAME_RULES, the unused exports are dropped, and event.js takes SEQ_MAX from ids.js.
  • Effort S. Risk very low.

#49 Shared: small dead code (debt).

  • attachments.js:353: M.attachments.said has no caller outside the module.
  • attachments.js:73 guards M.dom.sniffImage, which dom.js always provides.
  • M.ids.forgeBase, M.attachments.sizeOf and M.presence.running are used only by smoke.js. M.projectNames.said is used only internally and by smoke.js.
  • Proposal: drop the dead guard, and group the exports that only tests use.
  • Effort S. Risk very low.
  • Open question: i18n.js:36-37 and :53 remove the old maity.language localStorage key on every load. This is recorded at web/context/rendering.md:793, but the alpha has no legacy users. Confirm that the cleanup and its paragraph may go.