Skip to content

Commit 0598ba1

Browse files
committedMay 25, 2021
fix .. in encodingLength
1 parent 010aedb commit 0598ba1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

‎index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ name.decode = function (buf, offset) {
7474
name.decode.bytes = 0
7575

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

@@ -689,7 +689,8 @@ exports.AUTHENTIC_DATA = 1 << 5
689689
exports.CHECKING_DISABLED = 1 << 4
690690

691691
exports.encode = function (result, buf, offset) {
692-
if (!buf) buf = Buffer.allocUnsafe(exports.encodingLength(result))
692+
var allocing = !buf
693+
if (allocing) buf = Buffer.allocUnsafe(exports.encodingLength(result))
693694
if (!offset) offset = 0
694695

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

710711
exports.encode.bytes = offset - oldOffset
711712

713+
// just a quick sanity check
714+
if (allocing && exports.encode.bytes !== buf.length) {
715+
return buf.slice(0, exports.encode.bytes)
716+
}
717+
712718
return buf
713719
}
714720

0 commit comments

Comments
 (0)
Please sign in to comment.