From 46b2acc354bd825f0b521a4fe1004645fd98c2ef Mon Sep 17 00:00:00 2001 From: Lui Lui <40736418+lui01212@users.noreply.github.com> Date: Sun, 31 Dec 2023 10:00:00 +0700 Subject: [PATCH 1/2] test(client): expect the input limit in the autocomplete error Text over 64 code points gets the "1 to 11 letters and digits" message today, even when it holds only a few letters and digits after normalize. Check that the message names the limit before changing it (T-1). Signed-off-by: Lui Lui <40736418+lui01212@users.noreply.github.com> --- packages/client/test/requests.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) 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. From 25b4926930c7ca092b71c24d34a73803cedae0a7 Mon Sep 17 00:00:00 2001 From: Lui Lui <40736418+lui01212@users.noreply.github.com> Date: Sun, 31 Dec 2023 10:00:00 +0700 Subject: [PATCH 2/2] fix(client): name the input limit in the autocomplete error Text over 64 code points was turned into empty text before the check, so the caller read "1 to 11 letters and digits", which points at the wrong fault. Refuse it with its own message first, like the PHP client does. Signed-off-by: Lui Lui <40736418+lui01212@users.noreply.github.com> --- .changeset/name-autocomplete-input-limit.md | 5 +++++ packages/client/src/requests.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/name-autocomplete-input-limit.md 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.`);