@@ -50,6 +50,9 @@ const buf7 = Buffer.from('tést', 'latin1');
50
50
## Buffers and character encodings
51
51
<!-- YAML
52
52
changes:
53
+ - version: REPLACEME
54
+ pr-url: https://github.com/nodejs/node/pull/36952
55
+ description: Introduced `base64url` encoding.
53
56
- version: v6.4.0
54
57
pr-url: https://github.com/nodejs/node/pull/7111
55
58
description: Introduced `latin1` as an alias for `binary`.
@@ -106,6 +109,11 @@ string into a `Buffer` as decoding.
106
109
specified in [ RFC 4648, Section 5] [ ] . Whitespace characters such as spaces,
107
110
tabs, and new lines contained within the base64-encoded string are ignored.
108
111
112
+ * ` 'base64url' ` : [ base64url] [ ] encoding as specified in
113
+ [ RFC 4648, Section 5] [ ] . When creating a ` Buffer ` from a string, this
114
+ encoding will also correctly accept regular base64-encoded strings. When
115
+ encoding a ` Buffer ` to a string, this encoding will omit padding.
116
+
109
117
* ` 'hex' ` : Encode each byte as two hexadecimal characters. Data truncation
110
118
may occur when decoding strings that do exclusively contain valid hexadecimal
111
119
characters. See below for an example.
@@ -482,9 +490,10 @@ Returns the byte length of a string when encoded using `encoding`.
482
490
This is not the same as [ ` String.prototype.length ` ] [ ] , which does not account
483
491
for the encoding that is used to convert the string into bytes.
484
492
485
- For ` 'base64' ` and ` 'hex' ` , this function assumes valid input. For strings that
486
- contain non-base64/hex-encoded data (e.g. whitespace), the return value might be
487
- greater than the length of a ` Buffer ` created from the string.
493
+ For ` 'base64' ` , ` 'base64url' ` , and ` 'hex' ` , this function assumes valid input.
494
+ For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
495
+ return value might be greater than the length of a ` Buffer ` created from the
496
+ string.
488
497
489
498
``` js
490
499
const str = ' \u00bd + \u00bc = \u00be ' ;
@@ -3418,6 +3427,7 @@ introducing security vulnerabilities into an application.
3418
3427
[ `buffer.constants.MAX_STRING_LENGTH` ] : #buffer_buffer_constants_max_string_length
3419
3428
[ `buffer.kMaxLength` ] : #buffer_buffer_kmaxlength
3420
3429
[ `util.inspect()` ] : util.md#util_util_inspect_object_options
3430
+ [ base64url ] : https://tools.ietf.org/html/rfc4648#section-5
3421
3431
[ binary strings ] : https://developer.mozilla.org/en-US/docs/Web/API/DOMString/Binary
3422
3432
[ endianness ] : https://en.wikipedia.org/wiki/Endianness
3423
3433
[ iterator ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
0 commit comments