-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add path param validator (#834)
Usage will be added with later change.
- Loading branch information
childish-sambino
authored
Dec 5, 2022
1 parent
3ca7396
commit 31420e3
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
export const trim = (str, c = "\\s") => | ||
str.replace(new RegExp(`^([${c}]*)(.*?)([${c}]*)$`), "$2"); | ||
|
||
export function isValidPathParam(param: string): boolean { | ||
return ( | ||
param !== null && | ||
param !== undefined && | ||
!param.includes("/") && | ||
!param.includes("?") | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { isValidPathParam } from "../../../lib/base/utility"; | ||
|
||
describe("isValidPathParam", () => { | ||
it("should validate path params", () => { | ||
expect(isValidPathParam(null)).toBeFalsy(); | ||
expect(isValidPathParam(undefined)).toBeFalsy(); | ||
expect(isValidPathParam("with/slash")).toBeFalsy(); | ||
expect(isValidPathParam("with?question")).toBeFalsy(); | ||
|
||
expect(isValidPathParam("AC123")).toBeTruthy(); | ||
expect(isValidPathParam("space in name")).toBeTruthy(); | ||
}); | ||
}); |