Skip to content

Commit

Permalink
Merge pull request #16 from adamjosefus/development
Browse files Browse the repository at this point in the history
Bug of blank default value of mask param fixed
  • Loading branch information
adamjosefus authored Feb 19, 2022
2 parents 918cf77 + 4f9e8df commit 26c4610
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion helpers/Status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const enum Status {
}


export function getReasonPhrase(status: Status | number): string {
export function getReasonPhrase(status: number): string {
switch (status) {
case Status.S100_Continue:
return 'Continue';
Expand Down
7 changes: 6 additions & 1 deletion routers/MaskRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ export class MaskRouter extends Router implements IRouter {
};

const name = groups.name;
const defaultValue = groups.defaultValue ?? null;

const defaultValue = (v => {
if (v !== null && v !== '') return v;
return null;
})(groups.defaultValue?.trim() ?? null);

const expression = (v => {
if (v !== null) {
try {
Expand Down
4 changes: 2 additions & 2 deletions routers/RouterList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class RouterList implements IRouter {
}


setError(status: Status | number, serveResponse: ServeResponseType): void {
setError(status: number, serveResponse: ServeResponseType): void {
if (Number.isInteger(status)) {
throw new Error("Status must be integer.");
}
Expand All @@ -153,7 +153,7 @@ export class RouterList implements IRouter {
}


async getErrorReponse(status: Status | number, req: Request, params: Record<string, string> = {}): Promise<Response> {
async getErrorReponse(status: number, req: Request, params: Record<string, string> = {}): Promise<Response> {
const serveResponse = this.#errors.get(status);
const phrase = getReasonPhrase(status);

Expand Down
6 changes: 6 additions & 0 deletions tests/MaskRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ Deno.test("MaskRouter::parseParams", async () => {
action: "default",
},
},
{
mask: "[<s= >]",
pathname: "",
expectation: {
},
},
];


Expand Down

0 comments on commit 26c4610

Please sign in to comment.