Skip to content

Rule.io SDK


Rule.io SDK / rcml/src / sanitizeUrlKeepingForm

Function: sanitizeUrlKeepingForm()

sanitizeUrlKeepingForm(url): string

Defined in: rcml/src/email/sanitize-url-keeping-form.ts:50

Sanitise url like sanitizeUrl, but return it as given when it already is the same URL as the sanitised one, so normalisation alone (trailing slash, host case, punycode, ...) does not change it.

sanitizeUrl still decides what is rejected: an unsafe URL gives 'about:blank'. The given string (trimmed) is returned only when it contains no control, whitespace or zero-width characters and parses to exactly the URL the sanitiser approved. Anything the sanitiser decoded or stripped (HTML entities, percent-encoded characters, hidden characters) makes the two differ, and the sanitised string is returned instead.

Parameters ​

url ​

string

The URL to sanitise.

Returns ​

string

The URL as given, or sanitizeUrl(url) when it differs by more than normalisation, or 'about:blank' for an unsafe URL.

Example ​

ts
sanitizeUrlKeepingForm('https://facebook.com')   // 'https://facebook.com'
sanitizeUrlKeepingForm('https://Acme.Example')   // 'https://Acme.Example'
sanitizeUrlKeepingForm('javascript:alert(1)')    // 'about:blank'