Skip to content

Commit b3b236b

Browse files
committed
fix(service-settings): judge the declared format on the trimmed value
Both live readers (the mail transport's address check and the branding read) trim before use, so surrounding whitespace is not a format miss. Claude-Session: https://claude.ai/code/session_01UmqzD97e14iws6hmVhgZ5y Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2f2e8f0 commit b3b236b

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎.changeset/24882-settings-format-warning.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ The formats are the platform's existing grammars for the same words:
2121
- `phone`: digits, spaces and `+ ( ) - .`, at least five characters.
2222
- `color`: `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`.
2323

24-
Empty values and non-string values are not judged.
24+
Empty values and non-string values are not judged. Surrounding whitespace is ignored, because the readers trim it before use.
2525

2626
**Unchanged.** Status codes, response bodies, stored values, the `FieldError`s a refused save carries, and which overrides are in force. Under the standing rule 「甲」, refusing these values waits for the next major version.

‎packages/services/service-settings/src/settings-format-warning.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ describe('save door — a format miss is accepted and stored, and warned about o
193193
for (const colour of ['#abc', '#abcd', '#AABBCC', '#aabbccdd']) {
194194
expect((await put(http, 'branding', { accent_color: colour })).status).toBe(200);
195195
}
196+
// Surrounding whitespace is trimmed by both live readers before use, so it
197+
// is not a format miss; inner whitespace still is (the per-type cases above).
198+
expect((await put(http, 'company', { primary_contact_email: ' ops@example.com ' })).status).toBe(200);
196199
expect(warns).toEqual([]);
197200
});
198201

‎packages/services/service-settings/src/settings-service.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,10 @@ function firstFormatMiss(type: string, value: unknown): FormatMiss | null {
706706
const declared = DECLARED_VALUE_FORMATS.get(type);
707707
if (!declared) return null;
708708
if (typeof value !== 'string' || value.trim() === '') return null;
709-
if (declared.re.test(value)) return null;
709+
// Judged trimmed: both live readers trim before use (`plugin-email`'s
710+
// address check, `RuntimeConfigPlugin`'s branding read), so surrounding
711+
// whitespace is not a format any reader trips over. Inner whitespace is.
712+
if (declared.re.test(value.trim())) return null;
710713
return {
711714
type,
712715
code: declared.code,

0 commit comments

Comments
 (0)