Files
TiddlyWiki5/editions
pmario 005e175378 Fix RSOD when $tw.utils.addClass receives a class string with whitespace
PR #9251 replaced the manual setAttribute("class", ...) implementation of
$tw.utils.addClass/removeClass/toggleClass with direct Element.classList
calls. Unlike setAttribute, classList.add/remove/toggle throws
InvalidCharacterError on any token containing whitespace, so callers that
pass a whole class string (e.g. modal.js passing tiddler.fields.class)
now crash.

Manual repro on tw5-com: open SampleWizard, set the `class` field to
"aaa bbb", Done, open popup -> OK -> open nested popup -> RSOD.

Fix: split the className argument on whitespace in deprecated.js and feed
individual tokens to classList. A small splitClasses() helper keeps the
three functions symmetrical.

Adds adversarial regression tests in test-utils.js covering:
- ASCII whitespace variants (space, tab, CR, LF, mixed runs, padding)
- Unicode whitespace (U+00A0 non-breaking space)
- de-duplication across single and multiple calls
- remove/toggle no-op on missing tokens
- toggle with status undefined / true / false
- silent no-op for whitespace-only / empty / non-string / null input
- silent no-op when the element has no classList
2026-04-22 17:15:35 +02:00
..
2017-07-03 20:34:58 +01:00
2026-04-01 11:42:17 +01:00
2024-10-11 13:40:35 +01:00
2026-04-11 08:38:49 +01:00
2026-04-20 20:03:12 +01:00
2023-09-30 13:30:31 +01:00
2026-02-20 08:38:42 +00:00
2026-04-21 20:24:23 +01:00
2014-12-05 10:20:32 +00:00
2025-05-29 11:17:24 +01:00