feat: new helper functions to replace regexes #807

Implemented new StringUtil helper functions: splitCommaSeparated, sanitizeUrlPart, isValidFileName.
Added helper functions to HeaderUtil: matchesAuthorizationScheme, hasScheme.
Added unit tests for the new helper functions.
Refactored codebase to use helper functions instead of regexes if applicable.
This commit is contained in:
Wannes Kerckhove
2022-04-08 16:54:33 +02:00
committed by Joachim Van Herwegen
parent 1b7cc1ea3a
commit 283c301f08
18 changed files with 186 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
import { addHeader } from '../../util/HeaderUtil';
import { addHeader, hasScheme } from '../../util/HeaderUtil';
import { HttpHandler } from '../HttpHandler';
import type { HttpResponse } from '../HttpResponse';
@@ -11,7 +11,7 @@ export class WebSocketAdvertiser extends HttpHandler {
public constructor(baseUrl: string) {
super();
const socketUrl = new URL(baseUrl);
socketUrl.protocol = /^(?:http|ws):/u.test(baseUrl) ? 'ws:' : 'wss:';
socketUrl.protocol = hasScheme(baseUrl, 'http', 'ws') ? 'ws:' : 'wss:';
this.socketUrl = socketUrl.href;
}