File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -203,7 +203,23 @@ The character encodings currently supported by Node.js include:
203203
204204* ` 'binary' ` : Alias for ` 'latin1' ` .
205205
206- * ` 'hex' ` : Encode each byte as two hexadecimal characters.
206+ * ` 'hex' ` : Encode each byte as two hexadecimal characters. Data truncation
207+ may occur for unsanitized input. For example:
208+
209+ ``` js
210+ Buffer .from (' 1ag' , ' hex' );
211+ // Prints <Buffer 1a>, data truncated when first non-hexa-decimal value
212+ // ('g') encountered
213+
214+ Buffer .from (' 1a7g' , ' hex' );
215+ // Prints <Buffer 1a> , data truncated when data ends in single digit ('7').
216+
217+ Buffer .from (' 1634' , ' hex' );
218+ // Prints <Buffer 16 34> , fully qualified hexadecimal data
219+
220+ Buffer .from ((163 ).toString (16 ), ' hex' );
221+ // Prints <Buffer a3> , sanitized hexadecimal data
222+ ```
207223
208224Modern Web browsers follow the [ WHATWG Encoding Standard] [ ] which aliases
209225both ` 'latin1' ` and ` 'ISO-8859-1' ` to ` 'win-1252' ` . This means that while doing
You can’t perform that action at this time.
0 commit comments