-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HARMONY-1894: Rework label parameter handling and
add maximum length validation
- Loading branch information
1 parent
97401a7
commit 0c92c27
Showing
10 changed files
with
149 additions
and
10 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
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
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,27 @@ | ||
import { Response, NextFunction } from 'express'; | ||
import HarmonyRequest from '../models/harmony-request'; | ||
import { parseMultiValueParameter } from '../util/parameter-parsing-helpers'; | ||
|
||
/** | ||
* Express.js middleware to convert label parameter to an array (if needed) and add | ||
* it to the body of the request | ||
* | ||
* @param req - The client request | ||
* @param _res - The client response (not used) | ||
* @param next - The next function in the middleware chain | ||
*/ | ||
export default async function handleLabelParameter( | ||
req: HarmonyRequest, _res: Response, next: NextFunction, | ||
): Promise<void> { | ||
// Check if 'label' exists in the query parameters (GET), form-encoded body, or JSON body | ||
let label = req.query.label || req.body.label; | ||
|
||
// If 'label' exists, convert it to an array (if not already) and assign it to 'label' in the body | ||
if (label) { | ||
label = parseMultiValueParameter(label); | ||
req.body.label = label; | ||
} | ||
|
||
// Call next to pass control to the next middleware or route handler | ||
next(); | ||
} |
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
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
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
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
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,22 @@ | ||
/** | ||
* Generate a random string of a given length | ||
* | ||
* @param length - the desired string length | ||
* @param skipCodes - optional code points to skip, e.g., 0x002C for comma | ||
* @returns a random string of the given length | ||
*/ | ||
export function generateRandomString(length: number, skipCodes: number[] = []): string { | ||
let result = ''; | ||
|
||
for (let i = 0; i < length; i++) { | ||
// Generate a random Unicode code point from 0 to 65535 | ||
let randomCodePoint: number; | ||
do { | ||
randomCodePoint = Math.floor(Math.random() * 65536); | ||
} while (skipCodes.includes(randomCodePoint)); | ||
|
||
result += String.fromCharCode(randomCodePoint); | ||
} | ||
|
||
return result; | ||
} |
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
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