fix: limit the prompt template to 1,000 characters
storage.sync rejects any item over 8192 bytes, and the options page writes every field in one set(). An oversized template therefore made every later save fail, including changes to unrelated settings, with only a brief "Could not save settings". Cap the template at 1,000 UTF-16 units: maxlength on the input, and mergeSettings falls back to the default for a longer stored value, as it does for other out-of-range settings. Even a template of pasted control characters (six bytes each once JSON-escaped) stays under the quota; a test pins that arithmetic and another ties the HTML maxlength to the constant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { DEFAULT_SETTINGS, OPEN_IN_VALUES } from "./defaults.js";
|
||||
import { DEFAULT_SETTINGS, MAX_TEMPLATE_CHARS, OPEN_IN_VALUES } from "./defaults.js";
|
||||
|
||||
export function normalizeLanguage(value) {
|
||||
if (typeof value !== "string") return "";
|
||||
@@ -28,7 +28,7 @@ export function mergeSettings(stored) {
|
||||
if (OPEN_IN_VALUES.includes(stored.openIn)) {
|
||||
merged.openIn = stored.openIn;
|
||||
}
|
||||
if (typeof stored.promptTemplate === "string") {
|
||||
if (typeof stored.promptTemplate === "string" && stored.promptTemplate.length <= MAX_TEMPLATE_CHARS) {
|
||||
merged.promptTemplate = stored.promptTemplate;
|
||||
}
|
||||
return merged;
|
||||
|
||||
Reference in New Issue
Block a user