Skip to content

Commit 12a85bc

Browse files
timokoesslerhansott
andcommitted
Add normalizeLikeURLConstructor
Extracted from #595 Co-Authored-By: Hans Ott <[email protected]>
1 parent 9d3e7dc commit 12a85bc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* This function is used for urls, because they can contain a TAB, carriage return or line feed that is silently removed by the URL constructor.
3+
*
4+
* The WHATWG URL spec defines the following:
5+
* - Remove all ASCII tab or newline from input.
6+
* - An ASCII tab or newline is U+0009 TAB, U+000A LF, or U+000D CR.
7+
*
8+
* Also, backslashes are converted to forward slashes by the URL constructor.
9+
*
10+
* See https://url.spec.whatwg.org/#url-parsing
11+
*/
12+
export function normalizeLikeURLConstructor(url: string): string {
13+
return url.replace(/[\t\n\r]/g, "").replace(/\\/g, "/");
14+
}

0 commit comments

Comments
 (0)