Skip to content

Commit 99fc75e

Browse files
addaleaxevanlucas
authored andcommitted
doc: warn against filling buffer with invalid data
PR-URL: #17428 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 930f7a6 commit 99fc75e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

doc/api/buffer.md

+13
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,19 @@ Example: Fill a `Buffer` with a two-byte character
12531253
console.log(Buffer.allocUnsafe(3).fill('\u0222'));
12541254
```
12551255

1256+
If `value` is contains invalid characters, it is truncated; if no valid
1257+
fill data remains, no filling is performed:
1258+
1259+
```js
1260+
const buf = Buffer.allocUnsafe(5);
1261+
// Prints: <Buffer 61 61 61 61 61>
1262+
console.log(buf.fill('a'));
1263+
// Prints: <Buffer aa aa aa aa aa>
1264+
console.log(buf.fill('aazz', 'hex'));
1265+
// Prints: <Buffer aa aa aa aa aa>
1266+
console.log(buf.fill('zz', 'hex'));
1267+
```
1268+
12561269
### buf.includes(value[, byteOffset][, encoding])
12571270
<!-- YAML
12581271
added: v5.3.0

0 commit comments

Comments
 (0)