{bin2url:data}

Description

Encodes text or binary data into the URL-safe Base64url alphabet (RFC 4648 section 5). It runs standard base64, then replaces + with - and / with _, and removes the trailing = padding, so the result can be dropped into a URL path, query string, or filename without further escaping. Decode it back with url2bin. The parameter is not trimmed, so leading and trailing spaces are encoded as part of the data.

Parameters

data optional default (empty)

The text or binary data to encode. Any byte sequence is allowed. It is not trimmed, so leading and trailing whitespace is encoded as part of the data. Empty input produces empty output.

Examples

test{bin2url:Hello}
ExpectedSGVsbG8
ActualSGVsbG8
Base64url-encode a short string. The five characters Hello become SGVsbG8 - no padding, no special characters.
test{url2bin:{bin2url:round trip}}
Expectedround trip
Actualround trip
url2bin is the inverse of bin2url. Encoding a value and decoding it again returns the original text unchanged - the canonical roundtrip.
test{bin2url:foobar}
ExpectedZm9vYmFy
ActualZm9vYmFy
When the input length is a multiple of three bytes (here six), base64 needs no padding, so the URL-safe output is identical to plain base64.
test{bin2url:Hello, World!}
ExpectedSGVsbG8sIFdvcmxkIQ
ActualSGVsbG8sIFdvcmxkIQ
Plain base64 would end this value with == padding. bin2url removes the trailing = signs, which is the main reason the output is URL-safe.
test{bin2url: x }
ExpectedIHgg
ActualIHgg
bin2url does not trim its parameter. The leading and trailing spaces around x are encoded as real bytes, so the three characters (space, x, space) become IHgg.
test{bin2url:<b>x</b>}
ExpectedPGI-eDwvYj4
ActualPGI-eDwvYj4
The URL-safe alphabet replaces the standard base64 + and / characters with - and _. Here the encoded bytes include a - (where plain base64 would emit a +), so the value is safe in a URL without escaping.