(rawPadSettings: any = {})
| 186 | } |
| 187 | |
| 188 | static normalizePadSettings(rawPadSettings: any = {}): PadSettings { |
| 189 | const rawView = rawPadSettings.view ?? {}; |
| 190 | const result: PadSettings = { |
| 191 | enforceSettings: !!rawPadSettings.enforceSettings, |
| 192 | showChat: rawPadSettings.showChat == null ? settings.padOptions.showChat !== false : |
| 193 | !!rawPadSettings.showChat, |
| 194 | alwaysShowChat: !!rawPadSettings.alwaysShowChat, |
| 195 | chatAndUsers: !!rawPadSettings.chatAndUsers, |
| 196 | // Default to null (not 'en') so the client's l10n auto-detect chain |
| 197 | // (cookie -> navigator.language -> 'en' fallback) runs. Hardcoding 'en' |
| 198 | // forces English on every pad regardless of the browser's Accept-Language |
| 199 | // and broke #7586 (German system saw English pad UI in v2.7.0). |
| 200 | lang: typeof rawPadSettings.lang === 'string' ? rawPadSettings.lang : null, |
| 201 | view: { |
| 202 | showAuthorColors: rawView.showAuthorColors == null ? true : !!rawView.showAuthorColors, |
| 203 | showLineNumbers: rawView.showLineNumbers == null ? |
| 204 | settings.padOptions.showLineNumbers !== false : !!rawView.showLineNumbers, |
| 205 | rtlIsTrue: !!rawView.rtlIsTrue, |
| 206 | padFontFamily: typeof rawView.padFontFamily === 'string' ? rawView.padFontFamily : '', |
| 207 | fadeInactiveAuthorColors: rawView.fadeInactiveAuthorColors == null ? |
| 208 | settings.padOptions.fadeInactiveAuthorColors !== false : |
| 209 | !!rawView.fadeInactiveAuthorColors, |
| 210 | }, |
| 211 | }; |
| 212 | if (settings.enablePluginPadOptions) { |
| 213 | let totalBytes = 0; |
| 214 | for (const [k, v] of Object.entries(rawPadSettings)) { |
| 215 | if (!PLUGIN_KEY_RE.test(k)) continue; |
| 216 | const check = validatePluginValue(k, v, PLUGIN_KEY_MAX_BYTES); |
| 217 | if (!check.ok) { |
| 218 | // Drop and log. Persistence/broadcast still rejects the value, but |
| 219 | // the rest of the settings round-trip cleanly. |
| 220 | console.warn(`[normalizePadSettings] dropping ${k}: ${check.reason}`); |
| 221 | continue; |
| 222 | } |
| 223 | if (totalBytes + check.bytes > PLUGIN_TOTAL_MAX_BYTES) { |
| 224 | console.warn( |
| 225 | `[normalizePadSettings] dropping ${k}: combined ep_* size ` + |
| 226 | `would exceed cap ${PLUGIN_TOTAL_MAX_BYTES}B`); |
| 227 | continue; |
| 228 | } |
| 229 | totalBytes += check.bytes; |
| 230 | result[k] = v; |
| 231 | } |
| 232 | } |
| 233 | return result; |
| 234 | } |
| 235 | |
| 236 | apool() { |
| 237 | return this.pool; |
no test coverage detected