Skip to content

Commit b988118

Browse files
committed
address comment: fix typo and add unicode error validation
1 parent 8a90fd6 commit b988118

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/tools/args.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { z, type ZodString } from "zod";
22

33
const NO_UNICODE_REGEX = /^[\x20-\x7E]*$/;
4-
const NO_UNICODE_ERROR = "String cannot contain special characters or Unicode symbols";
4+
export const NO_UNICODE_ERROR = "String cannot contain special characters or Unicode symbols";
55

66
const ALLOWED_NAME_CHARACTERS_REGEX = /^[a-zA-Z0-9._-]+$/;
77
export const ALLOWED_CHARACTERS_ERROR = " can only contain letters, numbers, dots, hyphens, and underscores";
88

9-
const ALLLOWED_REGION_CHARACTERS_REGEX = /^[a-zA-Z0-9_-]+$/;
9+
const ALLOWED_REGION_CHARACTERS_REGEX = /^[a-zA-Z0-9_-]+$/;
1010
export const ALLOWED_REGION_CHARACTERS_ERROR = "Region can only contain letters, numbers, hyphens, and underscores";
1111

1212
const ALLOWED_CLUSTER_NAME_CHARACTERS_REGEX = /^[a-zA-Z0-9_-]+$/;
@@ -62,7 +62,7 @@ export const AtlasArgs = {
6262
.string()
6363
.min(1, "Region is required")
6464
.max(50, "Region must be 50 characters or less")
65-
.regex(ALLLOWED_REGION_CHARACTERS_REGEX, ALLOWED_REGION_CHARACTERS_ERROR),
65+
.regex(ALLOWED_REGION_CHARACTERS_REGEX, ALLOWED_REGION_CHARACTERS_ERROR),
6666

6767
password: (): z.ZodString =>
6868
z.string().min(1, "Password is required").max(100, "Password must be 100 characters or less"),

tests/unit/args.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ALLOWED_CHARACTERS_ERROR,
77
ALLOWED_REGION_CHARACTERS_ERROR,
88
ALLOWED_CLUSTER_NAME_CHARACTERS_ERROR,
9+
NO_UNICODE_ERROR,
910
} from "../../src/tools/args.js";
1011

1112
describe("Tool args", () => {
@@ -28,22 +29,22 @@ describe("Tool args", () => {
2829
const schema = CommonArgs.string();
2930

3031
// Unicode characters
31-
expect(() => schema.parse("héllo")).toThrow();
32-
expect(() => schema.parse("测试")).toThrow();
33-
expect(() => schema.parse("café")).toThrow();
32+
expect(() => schema.parse("héllo")).toThrow(NO_UNICODE_ERROR);
33+
expect(() => schema.parse("测试")).toThrow(NO_UNICODE_ERROR);
34+
expect(() => schema.parse("café")).toThrow(NO_UNICODE_ERROR);
3435

3536
// Emojis
36-
expect(() => schema.parse("🚀")).toThrow();
37-
expect(() => schema.parse("hello😀")).toThrow();
37+
expect(() => schema.parse("🚀")).toThrow(NO_UNICODE_ERROR);
38+
expect(() => schema.parse("hello😀")).toThrow(NO_UNICODE_ERROR);
3839

3940
// Control characters (below ASCII 32)
40-
expect(() => schema.parse("hello\nworld")).toThrow();
41-
expect(() => schema.parse("hello\tworld")).toThrow();
42-
expect(() => schema.parse("hello\0world")).toThrow();
41+
expect(() => schema.parse("hello\nworld")).toThrow(NO_UNICODE_ERROR);
42+
expect(() => schema.parse("hello\tworld")).toThrow(NO_UNICODE_ERROR);
43+
expect(() => schema.parse("hello\0world")).toThrow(NO_UNICODE_ERROR);
4344

4445
// Extended ASCII characters (above ASCII 126)
45-
expect(() => schema.parse("hello\x80")).toThrow();
46-
expect(() => schema.parse("hello\xFF")).toThrow();
46+
expect(() => schema.parse("hello\x80")).toThrow(NO_UNICODE_ERROR);
47+
expect(() => schema.parse("hello\xFF")).toThrow(NO_UNICODE_ERROR);
4748
});
4849

4950
it("should reject non-string values", () => {

0 commit comments

Comments
 (0)