Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
// Normalize byteOffset
if (typeof byteOffset === 'string') {
encoding = byteOffset
byteOffset = 0
byteOffset = undefined
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff
} else if (byteOffset < -0x80000000) {
Expand Down
9 changes: 9 additions & 0 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,12 @@ test('buffer.slice out of range', function (t) {
t.equal((new B('hallo')).slice(10, 2).toString(), '')
t.end()
})

test('lastIndexOf with encoding as second arg', function (t) {
const b = new B('abcdefghij')
t.equal(b.lastIndexOf('b'), 1)
t.equal(b.lastIndexOf('b', 'utf8'), 1)
t.equal(b.lastIndexOf('b', 'latin1'), 1)
t.equal(b.lastIndexOf('b', 'binary'), 1)
t.end()
})