diff --git a/.changeset/name-autocomplete-input-limit.md b/.changeset/name-autocomplete-input-limit.md new file mode 100644 index 0000000..5b8ccd2 --- /dev/null +++ b/.changeset/name-autocomplete-input-limit.md @@ -0,0 +1,5 @@ +--- +'@gatepost/client': patch +--- + +Name the 64 code point limit in the error for autocomplete text over it. diff --git a/packages/client/src/requests.ts b/packages/client/src/requests.ts index 91929da..35bfd6f 100644 --- a/packages/client/src/requests.ts +++ b/packages/client/src/requests.ts @@ -129,7 +129,11 @@ export function autocompleteRequest(q: string): { readonly typed: string; readonly request: GatewayRequest; } { - const typed = isOverInputLimit(q) ? '' : normalize(q); + if (isOverInputLimit(q)) { + const rule = `The text has more than ${String(INPUT_LIMIT)} code points.`; + throw clientError('invalid_input', `${rule} Send no call for it.`); + } + const typed = normalize(q); if (!QUERY.test(typed)) { const rule = 'The text must hold 1 to 11 letters and digits after normalize.'; throw clientError('invalid_input', `${rule} Send no call for empty text.`); diff --git a/packages/client/test/requests.test.ts b/packages/client/test/requests.test.ts index 7fa2d87..2548a68 100644 --- a/packages/client/test/requests.test.ts +++ b/packages/client/test/requests.test.ts @@ -146,6 +146,14 @@ describe('autocompleteRequest', () => { expect(failure(() => autocompleteRequest(overLimit)).code).toBe('invalid_input'); }); + it('names the input limit when the text is over it', () => { + // Five letters after normalize, so only the length is wrong. + const overLimit = 'FC 10'.padEnd(maxInputCodePoints + 1); + const { message } = failure(() => autocompleteRequest(overLimit)); + expect(message).toContain(`${String(maxInputCodePoints)} code points`); + expect(message).not.toContain('1 to 11'); + }); + it('counts code points, not UTF-16 units, for the input limit', () => { // Each mathematical bold capital is one code point in two UTF-16 units. NFKC makes it a // plain letter, so text at the limit still works.