Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/name-autocomplete-input-limit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gatepost/client': patch
---

Name the 64 code point limit in the error for autocomplete text over it.
6 changes: 5 additions & 1 deletion packages/client/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
Expand Down
8 changes: 8 additions & 0 deletions packages/client/test/requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down