Skip to content

Commit

Permalink
fix: rename algorithm to alg
Browse files Browse the repository at this point in the history
  • Loading branch information
Mokshit06 committed Dec 10, 2024
1 parent e8b7276 commit 70eaa22
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion deno/lib/__tests__/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ for (const str of invalidBase64URLStrings) {

test("jwt validations", () => {
const jwt = z.string().jwt();
const jwtWithAlg = z.string().jwt({ algorithm: "HS256" });
const jwtWithAlg = z.string().jwt({ alg: "HS256" });

// Valid JWTs
const validHeader = Buffer.from(JSON.stringify({ typ: "JWT", alg: "HS256" })).toString('base64url');
Expand Down
4 changes: 2 additions & 2 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export type ZodStringCheck =
| { kind: "trim"; message?: string }
| { kind: "toLowerCase"; message?: string }
| { kind: "toUpperCase"; message?: string }
| { kind: "jwt"; algorithm?: string; message?: string }
| { kind: "jwt"; alg?: string; message?: string }
| {
kind: "datetime";
offset: boolean;
Expand Down Expand Up @@ -1034,7 +1034,7 @@ export class ZodString extends ZodType<string, ZodStringDef, string> {
status.dirty();
}
} else if (check.kind === "jwt") {
if (!isValidJWT(input.data, check.algorithm)) {
if (!isValidJWT(input.data, check.alg)) {
ctx = this._getOrReturnCtx(input, ctx);
addIssueToContext(ctx, {
validation: "jwt",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ for (const str of invalidBase64URLStrings) {

test("jwt validations", () => {
const jwt = z.string().jwt();
const jwtWithAlg = z.string().jwt({ algorithm: "HS256" });
const jwtWithAlg = z.string().jwt({ alg: "HS256" });

// Valid JWTs
const validHeader = Buffer.from(JSON.stringify({ typ: "JWT", alg: "HS256" })).toString('base64url');
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export type ZodStringCheck =
| { kind: "trim"; message?: string }
| { kind: "toLowerCase"; message?: string }
| { kind: "toUpperCase"; message?: string }
| { kind: "jwt"; algorithm?: string; message?: string }
| { kind: "jwt"; alg?: string; message?: string }
| {
kind: "datetime";
offset: boolean;
Expand Down Expand Up @@ -1034,7 +1034,7 @@ export class ZodString extends ZodType<string, ZodStringDef, string> {
status.dirty();
}
} else if (check.kind === "jwt") {
if (!isValidJWT(input.data, check.algorithm)) {
if (!isValidJWT(input.data, check.alg)) {
ctx = this._getOrReturnCtx(input, ctx);
addIssueToContext(ctx, {
validation: "jwt",
Expand Down

0 comments on commit 70eaa22

Please sign in to comment.