Skip to content

Commit

Permalink
fix .. in encodingLength
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed May 25, 2021
1 parent 010aedb commit 0598ba1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ name.decode = function (buf, offset) {
name.decode.bytes = 0

name.encodingLength = function (n) {
if (n === '.') return 1
if (n === '.' || n === '..') return 1
return Buffer.byteLength(n.replace(/^\.|\.$/gm, '')) + 2
}

Expand Down Expand Up @@ -689,7 +689,8 @@ exports.AUTHENTIC_DATA = 1 << 5
exports.CHECKING_DISABLED = 1 << 4

exports.encode = function (result, buf, offset) {
if (!buf) buf = Buffer.allocUnsafe(exports.encodingLength(result))
var allocing = !buf
if (allocing) buf = Buffer.allocUnsafe(exports.encodingLength(result))
if (!offset) offset = 0

var oldOffset = offset
Expand All @@ -709,6 +710,11 @@ exports.encode = function (result, buf, offset) {

exports.encode.bytes = offset - oldOffset

// just a quick sanity check
if (allocing && exports.encode.bytes !== buf.length) {
return buf.slice(0, exports.encode.bytes)
}

return buf
}

Expand Down

0 comments on commit 0598ba1

Please # to comment.